+ // Compute actions
+ //
+
+ $to_user = FALSE;
+ $to_all = FALSE;
+ $to_room = FALSE;
+ $to_tabl = FALSE;
+ $is_normchat = FALSE;
+ /* for old isolation management $is_ticker = FALSE; */
+ $update_room = FALSE;
+
+ if (strcmp($msg, "/tav") == 0 ||
+ strncmp($msg, "/tav ", 5) == 0) {
+ do {
+ if ($user->stat != 'room' || $user->subst != 'sitdown') {
+ /* MLANG: "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>", "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>", "<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>" */
+ $msg = $mlang_brisk['tickmust'][$G_lang];
+ $to_user = show_notify($msg, 0, "chiudi", 400, 100);
+
+ break;
+ }
+
+ $table = $this->table[$user->table];
+
+ if ($table->wag_own != -1) {
+ // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
+ $msg = $mlang_brisk['tickjust'][$G_lang];
+ $to_user = show_notify($msg, 0, "chiudi", 400, 100);
+
+ break;
+ }
+
+ $dtime = $curtime - $table->wag_tout;
+ if ($dtime < EXPIRE_TIME_WAG) {
+ // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
+ $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
+ EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
+ $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
+
+ break;
+ }
+
+ $msg = substr($msg, 5);
+
+ $table->wag_set($user->idx_get(), $msg);
+ $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
+ $to_room = $to_user;
+ /* for old isolation management $is_ticker = TRUE; */
+ } while (0);
+ } // /tav chat command
+ // just for development use currently
+ else if (FALSE && strncmp($msg, "/out ", 5) == 0) {
+ fprintf(STDERR, "MOP OUT\n");
+ $target = substr($msg, 5);
+ $this->kickuser_by_name($target, GHOST_SESS_REAS_ANON);
+ }
+ else if (strncmp($msg, "/alarm ", 7) == 0) {
+ if (strncmp($msg, "/alarm to ", 10) == 0) {
+ $sp_pos = strpos($msg, " ", 10);
+ $target = substr($msg, 10, $sp_pos - 10);
+ $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
+ }
+ else {
+ $target = "";
+ $alarm_check = "/alarm ".$G_alarm_passwd." ";
+ }
+ do {
+ if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
+ /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
+ $msg = $mlang_brisk['alarpass'][$G_lang];
+ $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
+
+ break;
+ }
+
+ /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
+ $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
+ ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
+ $to_user = nickserv_msg($dt, $prestr);
+
+ $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
+ $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
+ /* MLANG: "chiudi" */
+ $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
+ } while (0);
+ } // /alarm chat command
+ else if (FALSE && strncmp($msg, "/listen ", 8) == 0) {
+ $arg = substr($msg, 8);
+
+ if (strcasecmp($arg, "isolation") == 0) {
+ $flags_old = 0;
+ if ($user->stat == 'room' && $user->subst == 'sitdown' &&
+ $user->table >= TABLES_AUTH_N) {
+ $to_user = nickserv_msg($dt, $mlang_brisk['listmust'][$G_lang]);
+
+ }
+ else {
+ $user->flags &= ~USER_FLAG_MAP_AUTH;
+ $user->flags |= USER_FLAG_ISOLAUTH;
+ $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
+ }
+ }
+ else {
+ $flags_old = $user->flags;
+ $user->flags &= ~USER_FLAG_MAP_AUTH;
+ $to_user = 'list_set(\'all\', true, \'\'); ';
+
+ }
+ // if from isolation redraw standup area
+ if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
+ $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
+
+ }
+ }
+ else if (strcmp($msg, "/authreq") == 0) {
+ if ($user->is_cert()) {
+ $to_user = sprintf('authbox(300,200);');
+ }
+ else {
+ /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>", "Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.", "Nickname <b>%s</b> già in uso." */
+ $to_user = nickserv_msg($dt, $mlang_brisk['authmust'][$G_lang]);
+ }
+ }
+ else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
+ if ($user->is_auth()) {
+ $to_user = sprintf('mesgtoadmbox(500,300);');
+ }
+ else {
+ /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
+ $to_user = nickserv_msg($dt, $mlang_brisk['mesgmust'][$G_lang]);
+ }
+ }
+ else if (FALSE && strncmp($msg, "/nick ", 6) == 0) {
+ log_main("chatt_send BEGIN");
+
+ do {
+ if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
+ $to_user = nickserv_msg($dt, $mlang_brisk['nickmust'][$G_lang]);
+ break;
+ }
+
+ $msg = "COMMAND ".$msg;
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+
+ if ($user_cur->is_active() == FALSE)
+ continue;
+ if (strcasecmp($user_cur->name,$name_new) == 0)
+ break;
+ }
+ if ($i < MAX_PLAYERS) {
+ $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
+ $to_user = nickserv_msg($dt, $prestr);
+ break;
+ }
+
+ /* MLANG: "<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>", "Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>" */
+ if ($user->is_auth()) {
+ if (strcasecmp($user->name,$name_new) != 0) {
+ if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
+ ($user->subst == 'standup' ||
+ ($user->subst != 'standup' && $this->table[$user->table]->auth_type == TABLE_AUTH_TY_PUBL)
+ )
+ ) {
+ $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+ $to_user .= $this->table[$i]->act_content($user);
+ }
+ }
+ else {
+ $to_user = nickserv_msg($dt, $mlang_brisk['authchan'][$G_lang]);
+ break;
+ }
+ }
+ }
+ $user->name = $name_new; // OK - nick changed
+ /* se nome gia' in uso, segnala cosa potrebbe capitare */
+ if ( ! $user->is_auth() ) {
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->users_load();
+ /* MLANG: "Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>" */
+ if ($bdb->login_exists(strtolower($name_new))) {
+ $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
+ $to_user .= nickserv_msg($dt, $prestr);
+ }
+ }
+ }
+
+ log_main("chatt_send start set");
+
+ $update_room = TRUE;
+ } while (0);
+ } // nick chat command
+ else if (strncmp($msg, "/info ", 6) == 0) {
+ do {
+ if (! $user->is_auth()) {
+ if ($mlang_indwr) {
+ $to_user = nickserv_msg($dt, $mlang_indwr['info_auth'][$G_lang]);
+ }
+ else {
+ $to_user = nickserv_msg($dt, "error");
+ }
+ break;
+ }
+ $info_user = substr($msg, 6);
+
+ echo $this->info_show($user, urldecode($info_user), $dt);
+ } while(0);
+ }
+ else if (strncmp($msg, "/st ", 4) == 0) {
+ log_main("chatt_send BEGIN");
+
+ do {
+ $st_str = substr($msg, 4);
+
+ if (strcasecmp($st_str, "normale") == 0) {
+ $st = USER_FLAG_S_NORM;
+ }
+ else if (strcasecmp($st_str, "pausa") == 0) {
+ $st = USER_FLAG_S_PAU;
+ }
+ else if (strcasecmp($st_str, "fuori") == 0) {
+ $st = USER_FLAG_S_OUT;
+ }
+ else if (strcasecmp($st_str, "cane") == 0) {
+ $st = USER_FLAG_S_DOG;
+ }
+ else if (strcasecmp($st_str, "cibo") == 0) {
+ $st = USER_FLAG_S_EAT;
+ }
+ else if (strcasecmp($st_str, "lavoro") == 0) {
+ $st = USER_FLAG_S_WRK;
+ }
+ else if (strcasecmp($st_str, "sigaretta") == 0) {
+ $st = USER_FLAG_S_SMK;
+ }
+ else if (strcasecmp($st_str, "presente") == 0) {
+ $st = USER_FLAG_S_EYE;
+ }
+ else if (strcasecmp($st_str, "coniglio") == 0) {
+ $st = USER_FLAG_S_RABB;
+ }
+ else if (strcasecmp($st_str, "calcio") == 0) {
+ $st = USER_FLAG_S_SOCC;
+ }
+ else if (strcasecmp($st_str, "pupo") == 0) {
+ $st = USER_FLAG_S_BABY;
+ }
+ else if (strcasecmp($st_str, "pulizie") == 0) {
+ $st = USER_FLAG_S_MOP;
+ }
+ else if (strcasecmp($st_str, "babbo") == 0) {
+ $st = USER_FLAG_S_BABBO;
+ }
+ else if (strcasecmp($st_str, "renna") == 0) {
+ $st = USER_FLAG_S_RENNA;
+ }
+ else if (strcasecmp($st_str, "pupazzo") == 0) {
+ $st = USER_FLAG_S_PUPAZ;
+ }
+ else if (strcasecmp($st_str, "vischio") == 0) {
+ $st = USER_FLAG_S_VISCH;
+ }
+ else {
+ /* MLANG: "Questo stato non esiste." */
+ $to_user = nickserv_msg($dt, $mlang_brisk['statunkn'][$G_lang]);
+ break;
+ }
+
+ log_main("chatt_send start set");
+ if (($user->flags & USER_FLAG_S_ALL) != $st) {
+ $update_room = TRUE;
+ $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
+ }
+ } while (0);
+ } // nick chat command
+
+ else { // normal chat line
+ $is_normchat = TRUE;
+ if (CHAT_ENABLED && $curtime < ($user->chat_ban + $user->chat_dlt)) {
+ $only_you = TRUE;
+ $user->chat_dlt = $user->chat_dlt * 2;
+ if ($user->chat_dlt > 120)
+ $user->chat_dlt = 120;
+ }
+ else if ($user->chat_lst == $msg)
+ $only_you = TRUE;
+ else if (CHAT_ENABLED && $curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
+ $user->chat_ban = $curtime;
+ $user->chat_dlt = 5;
+ $only_you = TRUE;
+ }
+ else {
+ $user->chat_ban = 0;
+ $user->chat_dlt = 0;
+ }
+
+ if ($only_you) {
+ $to_user = sprintf('chatt_sub("%s",[%d,"%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
+ }
+ else {
+ // TEMPORARY DISABLED UNTIL test user option will be available
+ // if ( TRUE && (!$user->is_auth() || $user->is_appr()) ) {
+ if (!$user->is_auth()) {
+ $to_user = nickserv_msg($dt, xcape("Visto l'elevato numero di molestatori che ultimamente hanno preso dimora su Brisk abbiamo deciso"));
+ $to_user .= nickserv_msg($dt, xcape("di disattivare temporaneamente la chat in room per i non registrati, non ce ne vogliate e buone feste."));
+ if (FALSE) {
+ $aug_head = array("Tanti", "Tantissimi", "Un enormità", "Un milione", "Un' esagerazione");
+ $aug_body = array("a tutti gli utenti", "a tutti gli uomini", "a tutte le donne", "a tutti gli utenti");
+ $aug_tail = array("di Brisk", "del sito", "della ciurma", "della comitiva", "del gruppo");
+
+ $auguri = sprintf("%s auguri %s %s.",
+ $aug_head[mt_rand(0, count($aug_head)-1)],
+ $aug_body[mt_rand(0, count($aug_body)-1)],
+ $aug_tail[mt_rand(0, count($aug_tail)-1)]);
+
+ $to_room = sprintf('chatt_sub("%s",[%d,"%s"],"%s");', $dt, $user->flags, xcape($user->name),
+ xcape($auguri));
+ }
+ }
+ else {
+ $to_user = sprintf('chatt_sub("%s",[%d,"%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
+ // temporary silentiation for troll (will became array check)
+ // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
+ $to_room = $to_user;
+ }
+ }
+
+ log_legal($curtime, $user->ip, $user,
+ ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
+
+ $user->chat_lst = "$msg";
+ $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
+ $user->chat_cur++;
+ }
+
+ if ($to_all) {
+ $to_room = $to_all;
+ $to_tabl = $to_all;
+ }
+
+ //
+ // Output to clients
+ //
+
+ if ($to_user != FALSE) {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] .= $to_user;
+ $user->step_inc();
+ }
+
+ if ($to_room != FALSE) {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+ if ($target != "" && $user_cur->name != $target)
+ continue;
+ if ($user_cur->is_active() == FALSE // is not active user
+ || $user_cur->stat == 'table' // or stat is 'table'
+ || $user->idx_get() == $i) // or the $user idx is equal to current var
+ continue;
+
+ if ($is_normchat == TRUE) {
+ // use MAP_AUTH to check if auth or isolation
+ if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
+ if ( ! $user->is_auth() ) {
+ continue;
+ }
+ }
+ }
+ /*
+ else if ($is_ticker) {
+ if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
+ if ($user->table >= TABLES_AUTH_N)
+ continue;
+ }
+ }
+ */
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
+ $user_cur->step_inc();
+ }
+ }
+
+ if ($to_tabl) {
+ // FIXME BRISK4: include for each kind of table
+ require_once("${G_base}briskin5/Obj/briskin5.phh");
+ // Before all align times with table timeout
+ for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
+ if (isset($this->match[$table_idx])) {
+ $bin5 = $this->match[$table_idx];
+
+ $bin5_table = $bin5->table[0];
+ for ($i = 0 ; $i < $bin5_table->player_n ; $i++) {
+ // stat must be "table" by definition
+ $bin5_user = $bin5->user[$i];
+
+ if ($target != "" && $bin5_user->name != $target)
+ continue;
+ log_main("writa: ".$user_mesg);
+ $bin5_user->comm[$bin5_user->step % COMM_N] = "gst.st = ".($bin5_user->step+1)."; ";
+ $bin5_user->comm[$bin5_user->step % COMM_N] .= $to_tabl;
+ $bin5_user->step_inc();
+ }
+ } // if (isset($this->match
+ } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
+ } // if ($to_tabl == true ...
+
+ if ($update_room) {
+ if ($user->stat == 'room' && $user->subst == 'standup') {
+ $this->standup_update($user);
+ }
+ else if ($user->stat == 'room' && $user->subst == 'sitdown') {
+ log_main("chatt_send pre table update");
+ $this->table_update($user);
+ log_main("chatt_send post table update");
+ }
+ } // if ($update_room ...
+
+ return;
+ } // function chatt_send( ...
+
+ function get_user($sess, &$idx)
+ {
+ GLOBAL $PHP_SELF;
+
+ if (validate_sess($sess)) {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if ($this->user[$i]->is_empty())
+ continue;
+ if (strcmp($sess, $this->user[$i]->sess) == 0) {
+ // find it
+ $idx = $i;
+ $ret = $this->user[$i];
+ return ($ret);
+ }
+ }
+ log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
+ // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
+ // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
+ }
+ else {
+ log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
+ }
+
+ return (FALSE);