/// <summary> /// Start main with dedicated_cfg /// </summary> /// <param name="config"></param> public Main(XmlDocument config) { InitializeComponent(); loadLang(); this.dedicatedConfig = config; this.chatColors = new ManiaColors(richTextBox1); Lama.log("NOTICE", "Open Main Form"); //Parse base config----------------------------------------------------------------------------------- XmlNode root = config[0]; XmlNode auth = root["authorization_levels"]; foreach (XmlNode node in auth.Childs) { switch (node["name"].Value) { case "SuperAdmin": this.login = "******"; this.passwd = node["password"].Value; break; } } this.port = int.Parse(root["system_config"]["xmlrpc_port"].Value); commonConstructor(); }
/// <summary> /// Start main in remote mode /// </summary> public Main(string login, string pass) { InitializeComponent(); loadLang(); this.chatColors = new ManiaColors(richTextBox1); Lama.log("NOTICE", "Open Main Form"); this.login = login; this.passwd = pass; this.adrs = Lama.remoteAdrs; this.port = Lama.remotePort; commonConstructor(); }
void startupRequests() { //Requêtes asyncRequest(GetStatus, res => { Hashtable ht = res.getHashTable(); setLabel(this.l_server, "Status : " + (string)ht["Name"]); }); asyncRequest(GetVersion, res => { setLabel(l_version, "Version : " + (string)res.getHashTable()["Version"]); }); asyncRequest(GetChatLines); asyncRequest(GetServerOptions, getServerOptions); asyncRequest(GetCurrentGameInfo, getCurrentGameInfo); asyncRequest(GetModeScriptSettings, getModeScriptSettings); asyncRequest(GetScriptName); asyncRequest(GetCurrentMapInfo, res => { var htcm = res.getHashTable(); setLabel(l_map, "Map : " + ManiaColors.getText((string)htcm["Name"])); }); asyncRequest("GetMapsDirectory", res => { this.mapPath = (string)res.Params[0]; }); asyncRequest(GetPlayerList, this.maxPlayers + this.maxSpectators, 0); asyncRequest(GetGuestList, this.maxPlayers + this.maxSpectators, 0); asyncRequest(GetBanList, this.maxPlayers + this.maxSpectators, 0); asyncRequest(GetBlackList, this.maxPlayers + this.maxSpectators, 0); asyncRequest(GetMapList, 999, 0); this.netStatsTimer = new Timer(); this.netStatsTimer.Tick += new EventHandler(netStatsTimer_Tick); this.netStatsTimer.Interval = 800; this.netStatsTimer.Start(); }
//Requests==================================================================================== void asyncRequest(String methodName, params object[] param) { if (param == null) { param = new object[] { } } ; this.handles.Add(this.client.AsyncRequest(methodName, param, asyncResult), methodName); } void asyncRequest(GbxCallCallbackHandler handler, String methodName, params object[] param) { if (param == null) { param = new object[] { } } ; this.client.AsyncRequest(methodName, param, handler); } void asyncRequest(String methodName, GbxCallCallbackHandler handler) { this.client.AsyncRequest(methodName, new object[] { }, handler); } //Main Async results========================================================================== void asyncResult(GbxCall res) { //Manage result------------------------------------------------------------------------ try { if (this.handles.ContainsKey(res.Handle) && !res.Error) { switch (this.handles[res.Handle]) { #region "Server Infos" ////////////////////////////////////////////////////////////////////////////////////////////////////// // Server Infos ///////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// case GetScriptName: var htscript = res.getHashTable(); string script = (string)htscript["CurrentValue"]; if (script.Contains(".Script.txt")) { script = subsep(script, 0, "."); } setLabel(this.l_gameMode, "GameMode : " + script); this.isTM = Enum.TryParse(script, out this.tmGameMode); if (this.isTM) { foreach (TMGameMode suit in (TMGameMode[])Enum.GetValues(typeof(TMGameMode))) { appendCombo(cb_serverGMScript, suit.ToString()); } } else { if (Enum.TryParse(script, out this.smGameMode)) { foreach (SMGameMode suit in (SMGameMode[])Enum.GetValues(typeof(SMGameMode))) { appendCombo(cb_serverGMScript, suit.ToString()); } } else { //Show select game dialog } } break; case GetMapList: Hashtable maps = res.getHashTable(); clearDg(dg_map); foreach (Hashtable map in maps) { addDgRow(dg_map, ManiaColors.getText((string)map["Name"]), map["Author"], map["Environnement"], map["LadderRanking"]); } break; case GetCurrentMapIndex: if (this.currentMapId != -1) { this.previousMapId = this.currentMapId; } this.currentMapId = (int)res.Params[0]; break; case SetScriptName: if ((bool)res.Params[0]) { setLabel(this.l_gameMode, "GameMode: " + this.cb_serverGMScript.Text); } break; #endregion #region "Chat" ////////////////////////////////////////////////////////////////////////////////////////////////////// // Chat ///////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// case GetChatLines: clearConsole(); var al = (ArrayList)res.Params[0]; foreach (object o in al) { string als = (string)o; if (als.Contains("$>") && als.Contains("$<")) { als = delseps(als, "[", "<"); als = als.Replace("$>]", "$000 :$fff"); } chatColors.write(als + "\n"); } break; #endregion #region "Players List" ////////////////////////////////////////////////////////////////////////////////////////////////////// // Players List ///////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// case GetPlayerList: ArrayList userList = (ArrayList)res.Params[0]; clearList(l_users); clearDg(dg_users); this.nbPlayers = userList.Count; setLabel(l_players, "Players : " + this.nbPlayers + "/" + this.maxPlayers); foreach (Hashtable user in userList) { this.playerList.Add(new SPlayerInfo { Login = (string)user["Login"], NickName = (string)user["NickName"], PlayerId = (int)user["PlayerId"], //............... }); addDgRow(dg_users, user["PlayerId"], ManiaColors.getText((string)user["NickName"]), user["Login"], user["LadderRanking"]); appendList(l_users, ManiaColors.getText((string)user["NickName"])); } break; case SendDisplayManialinkPageToId: break; case GetGuestList: break; case GetBlackList: break; case GetBanList: break; #endregion } } else { if (res.Error) { Lama.log("ERROR", "Answer for handle n° " + res.Handle + " named '" + this.handles[res.Handle] + "' Returned Error : " + res.ErrorString); } } //Send to plugins -------------------------------------------------------------------------------- foreach (InGamePlugin plug in Lama.inGamePlugins) { try { plug.onGbxAsyncResult(res); } catch (Exception e) { Lama.log("ERROR", "Plugins " + plug.PluginName + " throws Gbx Error :" + e.Message); } } this.handles.Remove(res.Handle); } catch (Exception e) { Lama.log("ERROR", "Answer for handle n°" + res.Handle + " throws a " + e.GetType().Name + "Exception : " + e.Message); } } //Specific AsyncResult void checkError(GbxCall res) { if (res.Error) { Lama.onError(this, "Error", "Error " + res.ErrorCode + " : " + res.ErrorString + "\n from request : " + res.MethodName); } } void getServerOptions(GbxCall res) { Hashtable ht = res.getHashTable(); setLabel(l_serverName, "Name : " + ManiaColors.getText((string)ht["Name"])); setLabel(l_serverDescritpion, "Description : " + ManiaColors.getText((string)ht["Comment"])); this.maxPlayers = (int)ht["CurrentMaxPlayers"]; this.maxSpectators = (int)ht["CurrentMaxSpectators"]; //Fill ServerOptions Tab setTextBoxText(tb_ingameName, (string)ht["Name"]); setTextBoxText(tb_description, (string)ht["Comment"]); setTextBoxText(tb_playerPass, (string)ht["Password"]); setTextBoxText(tb_specPass, (string)ht["PasswordForSpectator"]); setNumeric(n_playersLimit, maxPlayers); setNumeric(n_specsLimit, maxSpectators); setTextBoxText(tb_refereePass, (string)ht["RefereePassword"]); //TODO comboboxReferee setNumeric(n_voteTimeout, (int)ht["NextCallVoteTimeOut"]); setTextBoxText(tb_voteRatio, (string)ht["NextCallVoteRatio"]); int lm = (int)ht["NextLadderMode"]; setCheckBox(ch_ladder, (lm == 1)); setCheckBox(ch_p2pUp, (bool)ht["IsP2PUpload"]); setCheckBox(ch_p2pDown, (bool)ht["IsP2PDownload"]); setCheckBox(ch_autoSaveReplay, false); setCheckBox(ch_saveValReplay, false); setCheckBox(ch_keepPlayerSlot, false); setCheckBox(ch_mapDown, false); setCheckBox(ch_horns, false); } void getCurrentGameInfo(GbxCall res) { Hashtable ht = res.getHashTable(); } void getModeScriptSettings(GbxCall res) { Hashtable ht = res.getHashTable(); foreach (string key in ht.Keys) { switch (getType(ht[key])) { case 0: //String this.flowLayoutPanel1.Controls.Add(new StringScriptSetting(key, key, (string)ht[key])); break; case 1: //Int this.flowLayoutPanel1.Controls.Add(new NumericScriptSetting(key, key, (int)ht[key])); break; case 2: //Bool this.flowLayoutPanel1.Controls.Add(new BooleanScriptSetting(key, key, (bool)ht[key])); break; case 3: //Double this.flowLayoutPanel1.Controls.Add(new DoubleScriptSetting(key, key, (double)ht[key])); break; case -1: //Unknown Lama.log("ERROR", "Unable to get ScriptSetting type of : " + key + " : " + key.GetType()); break; } } } //CallBacks============================================================================================= void gbxCallBack(object sender, GbxCallbackEventArgs args) { switch (args.Response.MethodName) { //Race & Map infos #region "Server" case "ManiaPlanet.ServerStart": break; case "ManiaPlanet.ServerStop": break; case "ManiaPlanet.StatusChanged": break; case "ManiaPlanet.TunnelDataReceived": break; case "ManiaPlanet.Echo": break; case "ManiaPlanet.BillUpdated": break; #endregion #region "Scripts" case "ModeScriptCallback": break; case "ModeScriptCallbackArray": break; case "ScriptCloud.LoadData": break; case "ScriptCloud.SaveData": break; #endregion #region "ManiaPlanetMap" case "ManiaPlanet.BeginMap": setLabelColor(l_map, Color.Green); break; case "ManiaPlanet.BaginMatch": setLabelColor(l_map, Color.Green); break; case "ManiaPlanet.EndMap": setLabelColor(l_map, Color.Red); break; case "ManiaPlanet.EndMatch": setLabelColor(l_map, Color.Orange); break; #endregion #region "Race" case "TrackMania.EndRace": setLabelColor(l_map, Color.Orange); break; case "TrackMania.EndRound": break; case "TrackMania.ChallengeListModified": break; case "TrackMania.EndChallenge": setLabelColor(l_map, Color.Red); break; case "TrackMania.StatusChanged": int statusCode = (int)args.Response.Params[0]; setLabel(this.l_server, "Status : " + getStatus(statusCode)); break; case "TrackMania.BeginChallenge": setLabelColor(l_map, Color.Green); var ht = (Hashtable)args.Response.Params[0]; setLabel(l_map, "GameInfo : " + ManiaColors.getText((string)ht["Name"])); asyncRequest("GetCurrentMapIndex"); break; case "TrackMania.BeginRace": break; #endregion #region "Player" case "TrackMania.PlayerConnect": asyncRequest("GetPlayerList", this.maxPlayers + this.maxSpectators, 0); break; case "TrackMania.PlayerDisconnect": asyncRequest("GetPlayerList", this.maxPlayers + this.maxSpectators, 0); break; case "ManiaPlanet.PlayerChat": case "TrackMania.PlayerChat": var htPlayerChat = args.Response.Params; chatColors.write(htPlayerChat[1] + "$fff : " + htPlayerChat[2] + "\n"); break; case "TrackMania.PlayerInoChanged": break; case "TrackMania.PlayerAllies": break; case "TrackMania.PlayerManialinkPageAnswer": break; case "TrackMania.PlayerCheckpoint": break; case "TrackMania.PlayerFinish": break; case "TrackMania.PlayerIncoherence": break; #endregion } //Send to plugins---------------------------------------------------------------------- foreach (InGamePlugin plug in Lama.inGamePlugins) { plug.onGbxCallBack(sender, args); } } void gbxDisconnect(object sender) { FlatButton but = (FlatButton)getControl(this.b_xmlrpcConnect); but.BaseColor = Color.Green; enableControl(but, true); but.Enabled = true; but = (FlatButton)getControl(this.b_serverStarted); but.BaseColor = Color.Green; enableControl(but, true); this.netStatsTimer.Stop(); } #endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Autres Methodes ///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region "Other Methods" string getStatus(int code) { switch (code) { case 3: return("Running - Synchronisation"); case 4: return("Running - Play"); default: return(code.ToString()); } }