void ServerDB::save(Fl_Preferences &prefs) const { AutoLocker<const ServerDB * const> locker(this); std::string UIDs, group_UIDs; for(iterator iter = begin(); iter!= end(); iter++){ UIDs+= iter->get()->UID; UIDs.push_back(','); } UIDs.pop_back(); for(std::vector<std::string>::const_iterator iter = guts->groups.cbegin(); iter!= guts->groups.cend(); iter++){ group_UIDs+= *iter; group_UIDs.push_back(','); } group_UIDs.pop_back(); prefs.set("sys.server_uids", UIDs.c_str()); prefs.set("sys.sys.group_uids",group_UIDs.c_str()); std::for_each(begin(), end(), [&prefs](const ServerDataP& server){SaveServer(server.get(), prefs);}); prefs.set("sys.global.nickname", guts->global.nick.c_str()); prefs.set("sys.global.username", guts->global.user.c_str()); prefs.set("sys.global.realname", guts->global.real.c_str()); }
void ServerDB::open(Fl_Preferences &prefs){ AutoLocker<const ServerDB * const> locker(this); clear(); char *uid_list; if(!prefs.get("sys.server_uids", uid_list, "")){ prefs.set("sys.server_uids", ""); free(uid_list); return; } const char **server_uids = FJ::CSV::ParseString(uid_list); free(uid_list); char *groups; GetAndExist(prefs, "sys.group_uids", groups, ""); const char **group_uids = FJ::CSV::ParseString(groups); free(groups); for(int i = 0; group_uids[i]!=nullptr; i++){ guts->groups.push_back(group_uids[i]); } FJ::CSV::FreeParse(group_uids); for(int i = 0; server_uids[i]!=nullptr; i++){ struct ServerData *server = new ServerData(); server->UID = server_uids[i]; server->owner = this; LoadServer(server, prefs); for(std::vector<std::string>::const_iterator iter = server->group_UIDs.cbegin(); iter != server->group_UIDs.cend(); iter++){ start: if(std::find(guts->groups.cbegin(), guts->groups.cend(), *iter)==guts->groups.cend()){ guts->groups.push_back(*iter); goto start; } } push_back(ServerDataP(server)); } // The individual items are now owned by the ServerData. free(server_uids); GetAndExist(prefs, "sys.global.nickname", guts->global.nick, "KashyyykUser"); GetAndExist(prefs, "sys.global.username", guts->global.user, "KashyyykUser"); GetAndExist(prefs, "sys.global.realname", guts->global.real, "KashyyykUser"); }
void ServerDB::SaveServer(struct ServerData *server, Fl_Preferences &prefs){ const std::string ServerPrefix = std::string("server.")+server->UID + "."; prefs.set((ServerPrefix+"name").c_str(), server->name.c_str()); prefs.set((ServerPrefix+"nickname").c_str(), server->nick.c_str()); prefs.set((ServerPrefix+"username").c_str(), server->user.c_str()); prefs.set((ServerPrefix+"realname").c_str(), server->real.c_str()); prefs.set((ServerPrefix+"address").c_str(), server->address.c_str()); prefs.set((ServerPrefix+"port").c_str(), server->port); prefs.set((ServerPrefix+"ssl").c_str(), server->SSL); prefs.set((ServerPrefix+"globalidentity").c_str(), server->global); if(server->autojoin_channels.empty()) return; std::string autojoin; for(std::vector<std::string>::iterator iter = server->autojoin_channels.begin(); iter!=server->autojoin_channels.end(); iter++){ autojoin+=*iter; autojoin+=","; } autojoin.pop_back(); prefs.set((ServerPrefix+"autojoin").c_str(), autojoin.c_str()); }
void ServerDB::GroupDB::SaveGroup(struct GroupData *group, Fl_Preferences &prefs){ const std::string GroupPrefix = std::string("group.")+group->UID + "."; prefs.set((GroupPrefix+"name").c_str(), group->name.c_str()); GroupSet(prefs, GroupPrefix+"nickname", group->nick); GroupSet(prefs, GroupPrefix+"username", group->user); GroupSet(prefs, GroupPrefix+"realname", group->real); GroupSet(prefs, GroupPrefix+"ssl", group->SSL); GroupSet(prefs, GroupPrefix+"globalidentity", group->global); GroupSet(prefs, GroupPrefix+"authtype", group->auth_type); GroupSet(prefs, GroupPrefix+"auth", group->auth); }
void BlockWindow::setup() { reset(); help_button_ = new Fl_Button(0, 0, 20, 20, "?"); help_button_->callback((Fl_Callback *)help_cb, this); help_button_->shortcut('?'); play_button_ = new Fl_Button(80, (h() - 80) / 2, 80, 80, "@>"); play_button_->callback((Fl_Callback *)play_cb, this); play_button_->labelsize(44); play_button_->shortcut(' '); sound_ = new BlockSound(); prefs_.get("high_score", high_score_, 0); Fl::add_timeout(0.1, (Fl_Timeout_Handler)timeout_cb, (void *)this); }
// Handle mouse clicks, etc. int BlockWindow::handle(int event) { int j, k, mx, my, count; Block *b; Column *c; if (Fl_Double_Window::handle(event)) return (1); else if (interval_ < 0.0 || paused_) return (0); switch (event) { case FL_KEYBOARD: if (Fl::event_text()) { if (strcmp(Fl::event_text(), "+") == 0) up_level(); } break; case FL_PUSH : mx = w() - Fl::event_x() + BLOCK_SIZE; my = h() - Fl::event_y(); count = 0; b = 0; for (j = 0, c = columns_; !count && j < num_columns_; j ++, c ++) for (k = 0, b = c->blocks; !count && k < c->num_blocks; k ++, b ++) if (mx >= c->x && mx < (c->x + BLOCK_SIZE) && my >= b->y && my < (b->y + BLOCK_SIZE)) { if (b->bomb) count = bomb(b->color); else count = click(j, k); break; } if (count < 2) { for (j = 0, c = columns_; j < num_columns_; j ++, c ++) for (k = 0, b = c->blocks; k < c->num_blocks; k ++, b ++) if (b->color < 0) b->color = -b->color; } else { count --; if (b->bomb) { sound_->play_explosion(0.19 + 0.005 * count); interval_ *= 0.995; score_ += count; } else { sound_->play_explosion(0.09 + 0.005 * count); interval_ *= 0.999; score_ += count * count; } if (score_ > high_score_) { high_score_ = score_; prefs_.set("high_score", high_score_); } for (j = 0, c = columns_; j < num_columns_; j ++, c ++) for (k = 0, b = c->blocks; k < c->num_blocks; k ++, b ++) if (b->color < 0) b->color = BLOCK_BLAST; } return (1); } return (0); }
/* ============================================================================ Routine to create the PeripheralSetup Window and tabs ============================================================================ */ void cb_SocketSetup (Fl_Widget* w, void*) { Fl_Box* b; int port_num, enabled, telnet; // Get socket interface preferences virtualt_prefs.get("SocketPort", port_num, get_remote_port()); telnet = get_remote_telnet(); enabled = get_remote_enabled(); // Create Peripheral Setup window gsdw = new Fl_Window(300, 260, "Socket Configuration"); gsdw->callback(cb_sockdlg_win); /* Create enable checkbox */ sockdlg_ctrl.pEnable = new Fl_Check_Button(20, 20, 190, 20, "Enable Socket Interface"); sockdlg_ctrl.pEnable->callback(cb_sockdlg_enable); sockdlg_ctrl.pEnable->value(enabled); /* Create input field for for port number */ b = new Fl_Box(50, 50, 70, 20, "Port Number"); b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); sockdlg_ctrl.pPortNumber = new Fl_Input(160, 50, 60, 20, ""); sockdlg_ctrl.pPortNumber->align(FL_ALIGN_LEFT); sprintf(sockdlg_ctrl.sPortNumber, "%d", port_num); sockdlg_ctrl.pPortNumber->value(sockdlg_ctrl.sPortNumber); // Create checkbox for telnet mode sockdlg_ctrl.pTelnet = new Fl_Check_Button(50, 80, 200, 20, "Telnet Mode (std port is 23)"); sockdlg_ctrl.pTelnet->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); sockdlg_ctrl.pTelnet->value(telnet); // Deactivate port number and telnet mode if socket interface inactive if (!enabled) { sockdlg_ctrl.pPortNumber->deactivate(); sockdlg_ctrl.pTelnet->deactivate(); } b = new Fl_Box(20, 130, 120, 20, "Socket Port Status"); b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); sockdlg_ctrl.pStatus = new Fl_Box(50, 160, 200, 20, ""); sockdlg_ctrl.pStatus->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); update_port_status(); // Cancel button { Fl_Button* o = new Fl_Button(40, 200, 60, 30, "Cancel"); o->callback((Fl_Callback*) cb_sockdlg_cancel); } // Apply button sockdlg_ctrl.pApply = new Fl_Button(120, 200, 60, 30, "Apply"); sockdlg_ctrl.pApply->callback((Fl_Callback*) cb_sockdlg_apply); // OK button { Fl_Return_Button* o = new Fl_Return_Button(200, 200, 60, 30, "OK"); o->callback((Fl_Callback*)cb_sockdlg_OK); } gsdw->show(); }
/* ============================================================================ This routine applies the current settings in the dialog box and calls the remote API functions to setup and teardown the socket interface. It is called by the OK button also. ============================================================================ */ static void cb_sockdlg_apply(Fl_Widget* w, void*) { int port_num = 0, listen_port; int telnet; int enabled; // ============================================== // Get Port Number & telnet flag // ============================================== if (sockdlg_ctrl.pPortNumber->value() != NULL) port_num = atoi(sockdlg_ctrl.pPortNumber->value()); telnet = sockdlg_ctrl.pTelnet->value(); enabled = sockdlg_ctrl.pEnable->value(); // Test if the socket is enabled but the port is invalid if (enabled && ((port_num <= 0) || (port_num >= 65536))) { fl_alert("Please provide a port number between 1 and 65535"); return; } // Get the remote socket status listen_port = get_remote_listen_port(); // Test if the socket is enabled and the user want's it disabled if (!enabled) { // Check if the socket is currently active and shutdown if it is if (listen_port != 0) deinit_remote(); } // Test if we are enabling the socket for a different port number if (enabled && listen_port && (listen_port != port_num)) deinit_remote(); // Set the new port parameters set_remote_telnet(telnet); if (enabled) set_remote_port(port_num); else set_remote_port(0); enable_remote(enabled); // Update preferences virtualt_prefs.set("SocketPort", port_num); virtualt_prefs.set("SocketTelnetMode", telnet); virtualt_prefs.set("SocketEnabled", enabled); // Now enable the socket if the socket number is different if (enabled && (listen_port != port_num)) { init_remote(); } // If the apply button was pressed, then wait a bit for the port // status to change in the remote thread, then update the // port status if (w == sockdlg_ctrl.pApply) { SLEEP(500); update_port_status(); } }
void GroupSet<std::string[2]>(Fl_Preferences &prefs, const std::string &valuename, struct OptData<std::string[2]> &into){ int i = into.apply; prefs.set((valuename+".enabled").c_str(), i); prefs.set((valuename+"username").c_str(), into.value[0].c_str()); prefs.set((valuename+"password").c_str(), into.value[1].c_str()); }
void GroupSet<bool>(Fl_Preferences &prefs, const std::string &valuename, struct OptData<bool> &into){ int i = into.apply; prefs.set((valuename+".enabled").c_str(), i); i = into.value; prefs.set(valuename.c_str(), i); }