+ }
+
+ log_main("___");
+ log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
+ if ($user_cur->stat == "room") {
+ log_main("DOCUMENT.index.php from table");
+
+ $ret .= $this->table_content($user_cur, $table_idx);
+ $ret .= $this->standup_content($user_cur);
+
+ $ret .= $table->act_content($user_cur);
+
+
+ for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
+ if ($user_tab[$tab_idx] == $i)
+ break;
+
+ // for users that wakeup the room will be reconstructed by index_rd.php
+ if ($tab_idx < $user_tab_n) {
+ log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
+
+// ARRAY_POP DISABLED
+// if ($trans_delta == 0)
+// while (array_pop($user_cur->comm) != NULL);
+
+ $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
+ $user_cur->comm[$user_cur->step % COMM_N] = "";
+ $user_cur->step_inc();
+ $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
+ $user_cur->step_inc();
+ log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
+
+ continue;
+ }
+ log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
+
+ log_main("JOIN_WAKEUP more");
+
+ $ret .= $table->act_content($user_cur);
+
+ log_main("JOIN_WAKEUP end more");
+ }
+ log_wr("ROOM_JOIN_WAKEUP: ".$ret);
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step_inc();
+ }
+ }
+
+ /*
+ function info_show($user, $target, $dt)
+
+ if success return assoc. array with "ret" => 0 and other fields
+ else return an assoc. array with "ret: != 0 and "mesg" with an error description
+ */
+ function info_show($user, $target, $dt)
+ {
+ GLOBAL $G_lang, $mlang_brisk, $G_base;
+
+ $mesg = "";
+ $user_code = -1;
+ $ret = 0;
+
+ do {
+ if ($target == "") {
+ $ret = 1;
+ break;
+ }
+ if (($bdb = BriskDB::create()) == FALSE) {
+ $ret = 2;
+ break;
+ }
+ if ($target == $user->name) {
+ $ret = 3;
+ $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]);
+ break;
+ }
+ if (($user_item = $bdb->getitem_bylogin($target, $user_code)) == FALSE) {
+ $ret = 4;
+ break;
+ }
+ if (($guar_item = $bdb->getitem_bycode($user_item->guar_code_get())) != FALSE) {
+ $guar_login = $guar_item->login_get();
+ }
+ else {
+ $guar_login = "";
+ }
+ $user_tos_vers = $user_item->tos_vers_get();
+
+ $partyskill = $bdb->usersnet_partyskill($user->code, $user_item->code);
+
+ $widefriend = $bdb->usersnet_widefriend($user->code, $user_item->code);
+ $widefriend['skill'] = $bdb->usersnet_wideskill($user->code, $user_item->code);
+ $narrowfriend = $bdb->usersnet_narrowfriend($user->code, $user_item->code);
+ $narrowfriend['skill'] = $bdb->usersnet_narrowskill($user->code, $user_item->code);
+
+ if (($usersnet_item = $bdb->usersnet_bycode($user->code, $user_item->code,
+ $widefriend, $narrowfriend)) == FALSE) {
+ $usersnet_item = $bdb->usersnet_default($user->code, $user_item->code,
+ $widefriend, $narrowfriend);
+ }
+
+ if (versions_cmp($user_tos_vers, "1.2") < 0) {
+ $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($target));
+ }
+ else if ($guar_login == "") {
+ $mesg = sprintf($mlang_brisk['inf_nfd'][$G_lang], xcape($target));
+ }
+ } while (0);
+
+ if ($ret > 0 && $mesg == "") {
+ $mesg = sprintf($mlang_brisk['inf_err'][$G_lang], $ret);
+ }
+
+ if ($ret != 0) {
+ $jret = json_encode(array("ret" => $ret, "mesg" => $mesg));
+ }
+ else {
+ $jret = json_encode(array("ret" => 0,
+ "mesg" => "",
+ "login" => $target,
+ // FIXME: state internationalization
+ "state" =>
+ ($user_item->type & USER_FLAG_TY_APPR ? "Apprendista" :
+ ($user_item->type & USER_FLAG_TY_CERT ? "Certificato" :
+ ($user_item->type & (USER_FLAG_TY_NORM | USER_FLAG_TY_SUPER) ?
+ "Normale" : "Stato sconosciuto"))),
+ "guar" => ($user_item->type & USER_FLAG_TY_APPR ?
+ "" : $guar_login),
+ "party" => $partyskill,
+ "match" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->match_cnt) ,
+ "game" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->game_cnt),
+ "friend" => usersnet_friend_getlabel($usersnet_item->friend),
+ "skill" => $usersnet_item->skill,
+ "trust" => $usersnet_item->trust,
+ "widefriend" => $usersnet_item->widefriend,
+ "narrowfriend" => $usersnet_item->narrowfriend
+ ));
+ }
+
+ return $jret;
+ }
+
+ function info_save($user, $json_s)
+ {
+ GLOBAL $G_lang, $mlang_brisk, $G_base;
+
+ $mesg = "";
+ $user_code = -1;
+ $ret = 0;
+ $subret = 0;
+
+ do {
+ if (($json = json_decode($json_s)) == FALSE) {
+ $ret = 1;
+ break;
+ }
+
+ if (($bdb = BriskDB::create()) == FALSE) {
+ $ret = 2;
+ break;
+ }
+
+ if (($subret = $bdb->usersnet_save($user->code, $json)) != 0) {
+ $ret = 4000 + $subret;
+ break;
+ }
+ } while(0);
+
+ return ($ret);
+ }
+
+ function room_outstandup($user)
+ {
+ $this->room_sitdown($user, -1);
+ }
+
+ function table_update($user)
+ {
+ log_main("table_update: pre - USER: ".$user->name);
+
+ $table_idx = $user->table;
+
+ if ($table_idx > -1)
+ $table = $this->table[$table_idx];
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $ret = "";
+ $user_cur = $this->user[$i];
+ if ($user_cur->is_active() == FALSE || $user_cur->stat != 'room') // is not active user or the stat isn't 'room'
+ continue;
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ";
+ if ($table_idx > -1)
+ $ret .= $this->table_content($user_cur, $table_idx);
+
+ if ($user->idx_get() == $i) {
+ $ret .= $user->myname_innerHTML();
+ }
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step_inc();
+ }
+
+ log_main("table_update: post");
+ }
+
+ function room_sitdown($user, $table_idx)
+ {
+ log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
+
+ $train_app = "";
+
+ if ($table_idx > -1 && $table_idx < TABLES_N) {
+ $table = $this->table[$table_idx];
+
+ // wagon shutdown
+ if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+ if ($table->wag_own == $table->player[$i]) {
+ $train_app = sprintf("tra.rem(%d); ", $table_idx);
+ $table->wag_reset(time());
+ break;
+ }
+ }
+ }
+ }
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $ret = "";
+ $user_cur = $this->user[$i];
+ if ($user_cur->is_active() == FALSE || $user_cur->stat != 'room') // is not active user or the stat isn't 'room'
+ continue;
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
+ if ($table_idx > -1)
+ $ret .= $this->table_content($user_cur, $table_idx);
+ $ret .= $this->standup_content($user_cur);
+
+ if ($user->idx_get() == $i) {
+ $ret .= 'subst = "sitdown"; tra.hide(); ';
+ // clean the action buttons in other tables
+ for ($e = 0 ; $e < TABLES_N ; $e++) {
+ $ret .= $this->table[$e]->act_content($user_cur);
+ }
+ }
+ else if ($table_idx > -1) {
+ if ($table->player_n == PLAYERS_N) {
+
+ $ret .= $table->act_content($user_cur);
+ }
+ }
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step_inc();
+ }
+ }
+
+ function kickuser($user, $out_reas)
+ {
+ $curtime = time();
+
+ fprintf(STDERR, "MOP: GHOST_SESS: %d\n", $out_reas);
+
+ $this->ghost_sess->push($curtime, $user->sess, $out_reas);
+
+ fprintf(STDERR, "MOP: status out: %s %s %d\n", $user->stat, $user->subst, $user->idx);
+ if ($user->stat == 'table' && $user->subst != 'sitdown') {
+ $bin5 = &$this->match[$user->table];
+ $user_bin5 = &$bin5->user[$user->table_pos];
+ fprintf(STDERR, "MOP: status in: %s %s %d\n", $user_bin5->stat, $user_bin5->subst, $user_bin5->idx);
+ $bin5->table_wakeup($user_bin5);
+ $user->the_end = TRUE;
+ $this->room_wakeup($user);
+ return;
+ }
+
+ if ($user->stat == 'table' || $user->stat == 'room') {
+ $user->the_end = TRUE;
+ if ($user->subst == 'sitdown' || $user->stat == 'table') {
+ $this->room_wakeup($user);
+ }
+ else if ($user->subst == 'standup') {
+ fprintf(STDERR, "MOP: KICK here [%s]\n", btrace_line(debug_backtrace()));
+ $this->room_outstandup($user);
+ }
+ else {
+ log_rd2("LOGOUT FROM WHAT ???");
+ }
+ }
+ }
+
+ function kickuser_by_name($name, $out_reas)
+ {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_out = $this->user[$i];
+ if (strcmp($user_out->name, $name) == 0) {
+ return ($this->kickuser($user_out, $out_reas));
+ }
+ }
+ return FALSE;
+ }
+
+ function kickuser_by_sess($sess, $out_reas)
+ {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_out = $this->user[$i];
+ if (strcmp($user_out->sess, $sess) == 0) {
+ return ($this->kickuser($user_out, $out_reas));
+ }
+ }
+ return FALSE;
+ }
+
+ function kickuser_by_idx($idx, $out_reas)
+ {
+ $user_out = $this->user[$idx];
+ return ($this->kickuser($user_out, $out_reas));
+ }
+
+ function chatt_send($user, $mesg, $mlang_indwr = NULL)
+ {
+ GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
+ $only_you = FALSE;
+
+ // fprintf(STDERR, "WE ARE HERE: [%s]\n", $mesg);
+
+ // common settings
+ $msg = mb_substr($mesg, 6, 128, "UTF-8");
+ $curtime = time();
+ $dt = date("H:i ", $curtime);
+ $target = "";
+
+ //
+ // 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);
+ }
+
+ /*
+ * function add_user(&$brisk, &$sess, &$idx, $name, $pass, $ip, $header, $cookie)
+ *
+ * RETURN VALUE:
+ * if ($idx > -1 && ret == FALSE) => duplicated nick
+ * if ($idx == -2 && ret == FALSE) => invalid name
+ * if ($idx == -3 && ret == FALSE) => wrong password
+ * if ($idx == -1 && ret == FALSE) => no space left
+ * if ($idx == 0 && ret == user) => SUCCESS
+ * if ($idx == -($idx + 1) && ret == user) => SUCCESS (but the login exists in the auth db)
+ */
+
+ function add_user(&$sess, &$idx, $name, $pass, $ip, $header, $cookie)
+ {
+ GLOBAL $G_base;
+
+ $idx = 0;
+
+ $authenticate = FALSE;
+ $user_type = 0;
+ $login_exists = FALSE;
+ $ghost = -1;
+ $ghost_auth = FALSE;
+ $idx = -1;
+ $idfree = -1;
+ $code = FALSE;
+
+ if (($name_new = validate_name($name)) == FALSE) {
+ $idx = -2;
+ return (FALSE);
+ }
+
+ log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
+ if (validate_sess($sess) == FALSE)
+ $sess = "";
+
+ /* if pass != FALSE verify the login with pass */
+ log_auth("XXX", "auth1");
+
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->users_load();
+ if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
+ log_auth("XXX", "auth2");
+ $authenticate = $bdb->login_verify($name_new, $pass, $code);
+ log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
+
+ if ($authenticate != FALSE) {
+ $user_type = $authenticate->type_get();
+ }
+ else {
+ $idx = -3;
+ return (FALSE);
+ }
+ }
+ else {
+ $login_exists = $bdb->login_exists(strtolower($name_new));
+/*
+ TO ENABLE USER-LOGIN ONLY
+ - $login_exists = $bdb->login_exists(strtolower($name_new));
+ + // $login_exists = $bdb->login_exists(strtolower($name_new));
+ + // Force access with login and password
+ + $idx = -3;
+ + return (FALSE);
+*/
+ }
+ }
+ else {
+ // if db is down, send a warning and verify only current users
+ // no actions at this moment
+ }
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ /* free user ? */
+ if ($this->user[$i]->is_empty()) {
+ if ($idfree == -1) {
+ $idfree = $i;
+ }
+ continue;
+ }
+ if (strcmp($sess, $this->user[$i]->sess) == 0) {
+ if ($idx == -1) {
+ $idx = $i;
+ }
+ }
+ if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
+ if ($authenticate != FALSE) {
+ $ghost = $i;
+ $ghost_auth = $this->user[$i]->is_auth();
+ }
+ else {
+ $idx = $i;
+ break;
+ }
+ }
+ }
+ if ($idx == -1)
+ $idx = $idfree;
+
+ log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
+
+ /* there is another user logged with your account and you and him have authenticated => new user
+ get the session of the old user */
+ if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
+ /* swap session */
+
+ $ghost_user = $this->user[$ghost];
+ $curtime = time();
+ $this->ghost_sess->push($curtime, $ghost_user->sess, GHOST_SESS_REAS_ANOT);
+ $ghost_user->comm[$ghost_user->step % COMM_N] = "";
+ $ghost_user->step_inc();
+ if ($sess == "") {
+ $sess = uniqid("");
+ $ghost_user->sess = $sess;
+ }
+ else {
+ $ghost_user->sess = $sess;
+ }
+
+ // If user at the table we need to update the table data too
+ $table_idx = $ghost_user->table;
+ if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
+ require_once("${G_base}briskin5/Obj/briskin5.phh");
+ if (isset($this->match[$table_idx])) {
+ $bin5 = $this->match[$table_idx];
+
+ if ($bin5->the_end != TRUE) {
+ $bin5->user[$ghost_user->table_pos]->comm[$bin5->user[$ghost_user->table_pos]->step % COMM_N] = "";
+ $bin5->user[$ghost_user->table_pos]->step_inc();
+ $bin5->user[$ghost_user->table_pos]->sess = $sess;
+ }
+ }
+ }
+
+ $idx = $ghost;
+ if (defined('CURL_DE_SAC_VERS')) {
+ brisk_cds_execute($this, $ghost, $idx, $sess, $ip, $authenticate, $header);
+ }
+ return ($this->user[$ghost]);
+ }
+ else if ($idx != -1 && $i == MAX_PLAYERS) {
+ /* SUCCESS */
+ $curtime = time();
+ if ($sess == "") {
+ $sess = uniqid("");
+ $this->user[$idx]->sess = $sess;
+ }
+ else {
+ $this->user[$idx]->sess = $sess;
+ }
+ $this->user[$idx]->name = $name_new; // OK - add new user
+ $this->user[$idx]->stat_set("room");
+ $this->user[$idx]->step_set(0);
+ while (array_pop($this->user[$idx]->comm) != NULL);
+ $this->user[$idx]->subst = "standup";
+ $this->user[$idx]->lacc = $curtime;
+ $this->user[$idx]->laccwr = $curtime;
+ $this->user[$idx]->bantime = 0;
+ $this->user[$idx]->ip = $ip;
+
+ $this->user[$idx]->rec = $authenticate;
+ $this->user[$idx]->flags = $user_type;
+ $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
+ $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
+ log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
+
+ if ($authenticate != FALSE) {
+ $this->user[$idx]->code = $authenticate->code_get();
+ }
+ // fprintf(STDERR, "QQ %s: flag %x\n", __FUNCTION__, $this->user[$idx]->flags);
+ if ($ghost > -1) {
+ log_main("ghost: rename!");
+ $ghost_user = $this->user[$ghost];
+
+ if ($ghost_auth == FALSE) {
+ for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
+ $ghostname = 'ghost'.$sfx;
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if (strcmp("", $this->user[$i]->sess) == 0)
+ continue;
+
+ if (strcasecmp($this->user[$i]->name, $ghostname) == 0) {
+ $ghostname = '';
+ break;
+ }
+ }
+ if ($ghostname != '')
+ break;
+ }
+
+ $ghost_user->name = $ghostname;
+
+ if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
+ $this->standup_update($ghost_user);
+ }
+ else {
+ log_main("chatt_send pre table update");
+ $this->table_update($ghost_user);
+ log_main("chatt_send post table update");
+ }
+ } // if ($ghost_auth == FALSE
+ else {
+ // FIXME: cacciare il vecchio utente room && table (if needed)
+ $ghost_user->the_end = TRUE;
+ $ghost_user->lacc = 0;
+ $this->garbage_manager(TRUE);
+ }
+ } // if ($ghost > -1) {
+
+ $real_idx = $idx;
+ if ($login_exists)
+ $idx = -($idx + 1);
+ log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s] count [%d] name [%s] code [%s]", $idx, $sess, $name_new, count($this->user),$this->user[$real_idx]->name, $this->user[$real_idx]->code));
+
+ $ret = $this->user[$real_idx];
+ if (defined('CURL_DE_SAC_VERS')) {
+ brisk_cds_execute($this, $ghost, $real_idx, $sess, $ip, $authenticate, $header);
+ }
+ return ($ret);
+ }
+
+ return (FALSE);
+ }
+
+ function standup_update($user)
+ {
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+ if ($user_cur->is_active() == FALSE)
+ continue;
+
+ log_main("STANDUP START: ".$user_cur->stat);
+
+ if ($user_cur->stat == 'room') {
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
+ if ($user->idx_get() == $i) {
+ $user_cur->comm[$user_cur->step % COMM_N] .= $user->myname_innerHTML();
+ }
+ log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
+
+ $user_cur->step_inc();
+ }
+ }
+ }
+
+ function dump_data()
+ {
+ $brisk_ser = serialize($this);
+ $brisk_ser_len = mb_strlen($brisk_ser, "ASCII");
+ if (file_put_contents($this->crystal_filename, $brisk_ser) == $brisk_ser_len) {
+ return (TRUE);
+ }
+
+ return (FALSE);
+ }
+
+ function standup_content($user)
+ {
+ $ret = "";
+
+ if ($user->stat != 'room')
+ return;
+
+ $content = ' j_stand_cont( [ ';
+
+ $user_cur_id = $user->idx_get();
+ for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
+ if ($this->user[$i]->is_active() == FALSE // is not active user
+ || $this->user[$i]->stat != "room" // or the stat isn't 'room'
+ || $this->user[$i]->name == "") // or the name is empty, happens when user is reset (TODO: check it)
+ continue;
+
+ $flags = $this->user[$i]->flags;
+
+ // sql record exists AND last donate > 2013-01-01
+ if ($this->user[$i]->is_supp_custom()) {
+ $supp_comp_s = sprintf(', "%s"', $this->user[$i]->rec->supp_comp_get());
+ }
+ else {
+ $supp_comp_s = '';
+ }
+
+ if ($this->user[$i]->subst == "standup") {
+ $content .= sprintf('%s[ %d, "%s"%s ]',($ct > 0 ? ', ' : ''), $flags,
+ xcape($this->user[$i]->name), $supp_comp_s);
+ $ct++;
+ }
+ }
+ $content .= ' ]);';
+
+ return ($content);
+ }
+
+ function table_content($user, $table_idx)
+ {
+ $content = "";
+ $ret = "";
+ // TODO
+ //
+ // Si possono usare i dati nella classe table
+ //
+
+ $sess = $user->sess;
+ $table = $this->table[$table_idx];
+
+ if ($user->stat != 'room')
+ return;
+
+ $user_cur_id = $user->idx_get();
+ $content = "[ ";
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user_cur = $this->user[$table->player[$i]];
+
+ $flags = $user_cur->flags;
+
+ log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
+ if ($user_cur->is_supp_custom())
+ $supp_comp_s = sprintf(', "%s"', $user_cur->rec->supp_comp_get());
+ else
+ $supp_comp_s = '';
+
+ $content .= sprintf('%s[ %d, "%s"%s ]',($i == 0 ? '' : ', '), $flags,
+ xcape($user_cur->name), $supp_comp_s);
+ }
+
+ $content .= ' ]';
+
+ $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
+
+ return ($ret);
+ }
+
+ function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
+ {
+ GLOBAL $G_ban_list, $G_black_list, $G_cloud_smasher;
+
+ // printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
+
+ // fprintf(STDERR, "\n\n\n PRE_BLACK [%s]\n\n\n", $addr);
+ if ($this->black_check($addr)) {
+ // TODO: waiting async 5 sec before close
+ // fprintf(STDERR, "\n\n\n BLACK CHECK\n\n\n");
+ return (FALSE);
+ }
+ if ($path != "" && $path != "index.php") {
+ if ($this->cloud_check($addr)) {
+ // TODO: waiting async 5 sec before close
+ return (FALSE);
+ }
+ }
+
+ $enc = get_encoding($header);
+ if (isset($header['User-Agent'])) {
+ if (strstr($header['User-Agent'], "MSIE")) {
+ $transp_type = "htmlfile";
+ }
+ else {
+ $transp_type = "xhr";
+ }
+ }
+ else {
+ $transp_type = "iframe";
+ }
+ force_no_cache($header_out);
+
+ switch ($path) {
+ case "":
+ case "index.php":
+ ob_start();
+ index_main($this, $transp_type, $header, $header_out, $addr, $get, $post, $cookie);
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ // fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content);
+ $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
+ return TRUE;
+
+ break;
+ case "index_wr.php":
+ //
+ // Enhance required: in the POST case, after the header you must get content
+ // from the socket, waiting if necessary
+ //
+
+ ob_start();
+ index_wr_main($this, $addr, $get, $post, $cookie);
+ $content = ob_get_contents();
+ ob_end_clean();
+
+ $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
+ return TRUE;
+
+ break;
+ case "index_rd.php":
+ case "index_rd_wss.php":
+ if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE)
+ $transp = "iframe";
+ if ($transp == 'websocket' || $transp == 'websocketsec')
+ $enc = 'plain';
+
+ do {
+ if (!isset($cookie['sess'])
+ || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) {
+
+ $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE);
+
+ $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
+ return TRUE;
+
+ break;