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::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::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::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); }
// 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); }
/* ============================================================================ 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); }