float IsFavorite(string srv) { string p; float i, n; if(srv == "") return FALSE; srv = netaddress_resolve(srv, 26000); if(srv == "") return FALSE; p = crypto_getidfp(srv); n = tokenize_console(cvar_string("net_slist_favorites")); for(i = 0; i < n; ++i) { if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { if(p) if(argv(i) == p) return TRUE; } else { if(srv == netaddress_resolve(argv(i), 26000)) return TRUE; } } return FALSE; }
float XonoticColorpicker_mouseDrag(entity me, vector coords) { float i; for(;;) { i = me.controlledTextbox.cursorPos; if(i >= 2) { if(substring(me.controlledTextbox.text, i-2, 1) == "^") if(strstrofs("0123456789", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0) { me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); continue; } } if(i >= 5) { if(substring(me.controlledTextbox.text, i-5, 2) == "^x") if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-3, 1), 0) >= 0) if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-2, 1), 0) >= 0) if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0) { me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); continue; } } break; } vector margin; margin = me.imagemargin; if(coords_x >= margin_x) if(coords_y >= margin_y) if(coords_x <= 1 - margin_x) if(coords_y <= 1 - margin_y) me.controlledTextbox.enterText(me.controlledTextbox, rgb_to_hexcolor(hslimage_color(coords, margin))); return 1; }
void enterTextInputBox(entity me, string ch) { float i; for(i = 0; i < strlen(ch); ++i) if(strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1) return; if(strlen(ch) + strlen(me.text) > me.maxLength) return; me.setText(me, strcat(substring(me.text, 0, me.cursorPos), ch, substring(me.text, me.cursorPos, strlen(me.text) - me.cursorPos))); me.cursorPos += strlen(ch); }
void XonoticPlayerList_drawListBoxItem(entity me, float i, vector absSize, float isSelected) { string s; string score; float t; vector rgb; t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM)); if(t == 1) rgb = colormapPaletteColor(4, 0); else if(t == 2) rgb = colormapPaletteColor(13, 0); else if(t == 3) rgb = colormapPaletteColor(12, 0); else if(t == 4) rgb = colormapPaletteColor(9, 0); else rgb = '1 1 1'; s = me.getPlayerList(me, i, PLAYERPARM_NAME); score = me.getPlayerList(me, i, PLAYERPARM_SCORE); if(substring(score, strlen(score) - 10, 10) == ":spectator") { score = "-666"; } else { if((t = strstrofs(score, ":", 0)) >= 0) score = substring(score, 0, t); if((t = strstrofs(score, ",", 0)) >= 0) score = substring(score, 0, t); } s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize); score = draw_TextShortenToWidth(score, me.columnScoreSize, 0, me.realFontSize); draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 1, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', 1, 1); draw_Text(me.realUpperMargin2 * eY + (me.columnScoreOrigin + 1.00 * (me.columnScoreSize - draw_TextWidth(score, 1, me.realFontSize))) * eX, score, me.realFontSize, rgb, 1, 0); }
void ToggleFavorite(string srv) { string s, s0, s1, s2, srv_resolved, p; float i, n, f; srv_resolved = netaddress_resolve(srv, 26000); p = crypto_getidfp(srv_resolved); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); f = 0; for(i = 0; i < n; ++i) { if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { if(p) if(argv(i) != p) continue; } else { if(srv_resolved != netaddress_resolve(argv(i), 26000)) continue; } s0 = s1 = s2 = ""; if(i > 0) s0 = substring(s, 0, argv_end_index(i - 1)); if(i < n-1) s2 = substring(s, argv_start_index(i + 1), -1); if(s0 != "" && s2 != "") s1 = " "; cvar_set("net_slist_favorites", strcat(s0, s1, s2)); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); f = 1; --i; } if(!f) { s1 = ""; if(s != "") s1 = " "; if(p) cvar_set("net_slist_favorites", strcat(s, s1, p)); else cvar_set("net_slist_favorites", strcat(s, s1, srv)); } resorthostcache(); }
void ServerList_TypeSort_Click(entity btn, entity me) { string s, t; float i, m; s = me.filterString; m = strstrofs(s, ":", 0); if(m >= 0) { s = substring(s, 0, m); while(substring(s, m+1, 1) == " ") // skip spaces ++m; } else s = ""; for(i = 1; ; ++i) // 20 modes ought to be enough for anyone { t = GametypeNameFromType(i); if(i > 1) if(t == GametypeNameFromType(0)) // it repeats (default case) { // no type was found // choose the first one s = t; break; } if(s == GametypeNameFromType(i)) { // the type was found // choose the next one s = GametypeNameFromType(i + 1); if(s == GametypeNameFromType(0)) s = ""; break; } } if(s != "") s = strcat(s, ":"); s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1)); me.controlledTextbox.setText(me.controlledTextbox, s); me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0); me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0); //ServerList_Filter_Change(me.controlledTextbox, me); }
void XonoticServerList_refreshServerList(entity me, float mode) { // 0: just reparametrize // 1: also ask for new servers // 2: clear //print("refresh of type ", ftos(mode), "\n"); /* if(mode == 2) // borken { // clear list localcmd("net_slist\n"); me.needsRefresh = 1; // net_slist kills sort order, so we need to restore it later } else */ { float m, o; string s, typestr, modstr; s = me.filterString; m = strstrofs(s, ":", 0); if(m >= 0) { typestr = substring(s, 0, m); s = substring(s, m + 1, strlen(s) - m - 1); while(substring(s, 0, 1) == " ") s = substring(s, 1, strlen(s) - 1); } else typestr = ""; modstr = cvar_string("menu_slist_modfilter"); m = SLIST_MASK_AND - 1; resethostcachemasks(); if(!me.filterShowFull) { sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support } if(!me.filterShowEmpty) sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL); if(typestr != "") sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH); if(modstr != "") { if(substring(modstr, 0, 1) == "!") sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL); else sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL); } m = SLIST_MASK_OR - 1; if(s != "") { sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH); } o = 2; // favorites first if(me.currentSortOrder < 0) o |= 1; // descending sethostcachesort(me.currentSortField, o); resorthostcache(); if(mode >= 1) refreshhostcache(); } }
void XonoticServerList_refreshServerList(entity me, float mode) { // 0: just reparametrize // 1: also ask for new servers // 2: clear //print("refresh of type ", ftos(mode), "\n"); /* if(mode == 2) // borken { // clear list localcmd("net_slist\n"); me.needsRefresh = 1; // net_slist kills sort order, so we need to restore it later } else */ { float m, o, i, n; // moin moin string s, typestr, modstr; s = me.filterString; m = strstrofs(s, ":", 0); if(m >= 0) { typestr = substring(s, 0, m); s = substring(s, m + 1, strlen(s) - m - 1); while(substring(s, 0, 1) == " ") s = substring(s, 1, strlen(s) - 1); } else typestr = ""; modstr = cvar_string("menu_slist_modfilter"); m = SLIST_MASK_AND - 1; resethostcachemasks(); // ping: reject negative ping (no idea why this happens in the first place, engine bug) sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL); // show full button if(!me.filterShowFull) { sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support } // show empty button if(!me.filterShowEmpty) sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL); // gametype filtering if(typestr != "") sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH); // mod filtering if(modstr != "") { if(substring(modstr, 0, 1) == "!") sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL); else sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL); } // server banning n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " "); for(i = 0; i < n; ++i) if(argv(i) != "") sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH); m = SLIST_MASK_OR - 1; if(s != "") { sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH); } o = 2; // favorites first if(me.currentSortOrder < 0) o |= 1; // descending sethostcachesort(me.currentSortField, o); resorthostcache(); if(mode >= 1) refreshhostcache(); } }