Ejemplo n.º 1
0
 //Start
 private void flatButton1_Click(object sender, EventArgs e)
 {
     try
     {
         int index = Lama.servers.getKeyFromValue(flatComboBox1.Text);
         start(index);
     }
     catch (Exception)
     {
         Lama.onError(this, "Error", "Undefined server : " + flatComboBox1.Text);
     }
 }
Ejemplo n.º 2
0
        private void b_newMatch_Click(object sender, EventArgs e)
        {
            string file = tb_matchFile.Text;
            string path = mapPath + @"MatchSettings\" + file;

            if (!File.Exists(path))
            {
                try
                {
                    File.Create(path).Close();
                    this.matchSettings = new XmlDocument(path);
                }
                catch (Exception er)
                {
                    Lama.onException(this, er);
                }
            }
            else
            {
                Lama.onError(this, "Error", "The file : " + file + " already exists !");
            }
        }
Ejemplo n.º 3
0
        //Remove
        private void flatButton3_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Are you sure ?", "Are you sure to remove" + flatComboBox1.SelectedText, MessageBoxButtons.YesNo);

            if (res == DialogResult.No)
            {
                return;
            }

            int     index = Lama.servers.getKeyFromValue(flatComboBox1.Text);
            XmlNode cfg   = Lama.mainConfig[0]["servers"].getChildByAttribute("id", index.ToString());

            try
            {
                if (cfg["remote"].getAttibuteV("value").ToUpper().Equals("FALSE"))
                {
                    Directory.Delete(Application.StartupPath + @"\Servers\" + index + @"\", true);
                }
            }
            catch (Exception dirEx) {
                Lama.onException(this, dirEx);
            }

            //Update Main Config
            int total = Lama.mainConfig[0]["servers"].removeChildsByAttribute("server", "id", index.ToString());


            if (total != 1)
            {
                Lama.onError(this, "Error", "Unable to delete server from main config, nodes affected = ");
            }
            else
            {
                Lama.mainConfig.save();
                load();
            }
        }
Ejemplo n.º 4
0
        void saveDedicated()
        {
            Lama.log("NOTICE", "Save Dedicated");
            try
            {
                XmlNode root = this.dedicated_config[0];  //dedicated

                //Authorisations --------------------------------------------------------------------------
                XmlNode auth = root["authorization_levels"];
                foreach (XmlNode lvl in auth.getChildList("level"))
                {
                    switch (lvl["name"].Value)
                    {
                    case "SuperAdmin":
                        lvl["password"].Value = tb_superPass.Text;
                        break;

                    case "Admin":
                        lvl["password"].Value = tb_adminPass.Text;
                        break;

                    case "User":
                        lvl["password"].Value = tb_userPass.Text;
                        break;
                    }
                }

                //Master Account --------------------------------------------------------------------------
                XmlNode master = root["masterserver_account"];
                master["login"].Value          = tb_serverLogin.Text;
                master["password"].Value       = tb_ServerPass.Text;
                master["validation_key"].Value = tb_validKey.Text;


                //Server Options --------------------------------------------------------------------------
                XmlNode servOptions = root["server_options"];
                servOptions["name"].Value               = tb_ingameName.Text;
                servOptions["comment"].Value            = tb_description.Text;
                servOptions["hide_server"].Value        = cb_hiddenServer.SelectedIndex.ToString();
                servOptions["password"].Value           = tb_playerPass.Text;
                servOptions["password_spectator"].Value = tb_specPass.Text;
                servOptions["referee_password"].Value   = tb_refereePass.Text;
                servOptions["callvote_ratio"].Value     = tb_voteRatio.Text;

                servOptions["callvote_timeout"].Value        = n_voteTimeout.Value.ToString();
                servOptions["max_players"].Value             = n_playersLimit.Value.ToString();
                servOptions["max_spectators"].Value          = n_specsLimit.Value.ToString();
                servOptions["clientinputs_maxlatency"].Value = n_maxLat.Value.ToString();

                servOptions["keep_player_slots"].Value = ch_keepPlayerSlot.Checked.ToString();

                if (ch_ladder.Checked)
                {
                    servOptions["ladder_mode"].Value = "forced";
                }
                else
                {
                    servOptions["ladder_mode"].Value = "incative";
                }

                servOptions["enable_p2p_upload"].Value           = ch_p2pUp.Checked.ToString();
                servOptions["enable_p2p_download"].Value         = ch_p2pDown.Checked.ToString();
                servOptions["allow_map_download"].Value          = ch_mapDown.Checked.ToString();
                servOptions["autosave_replays"].Value            = ch_autoSaveReplay.Checked.ToString();
                servOptions["autosave_validation_replays"].Value = ch_saveValReplay.Checked.ToString();

                servOptions["referee_validation_mode"].Value = cb_refereeValid.SelectedIndex.ToString();
                servOptions["disable_horns"].Value           = ch_horns.Checked.ToString();


                //System Config --------------------------------------------------------------------------
                XmlNode systemConfig = root["system_config"];

                systemConfig["connection_uploadrate"].Value      = n_UpRate.Value.ToString();
                systemConfig["connection_downloadrate"].Value    = n_DownRate.Value.ToString();
                systemConfig["packetassembly_threadcount"].Value = n_paThreadCount.Value.ToString();

                systemConfig["allow_spectator_relays"].Value = ch_allowSpecRelay.Checked.ToString();

                systemConfig["p2p_cache_size"].Value = n_p2pCacheSize.Value.ToString();

                systemConfig["server_port"].Value     = tb_ServerPort.Text;
                systemConfig["server_p2p_port"].Value = tb_p2pPort.Text;
                systemConfig["xmlrpc_port"].Value     = tb_XmlRpcPort.Text;
                systemConfig["proxy_url"].Value       = tb_proxy.Text;

                systemConfig["xmlrpc_allowremote"].Value = ch_xmlRpcRemote.Checked.ToString();
                systemConfig["use_proxy"].Value          = ch_proxy.Checked.ToString();


                systemConfig["title"].Value = tb_title.Text;
                this.dedicated_config.save();
            }
            catch (Exception er)
            {
                Lama.log("ERROR", "[ConfigServ]Unable to save dedicated : " + er.Message);
                Lama.onError(this, "Error", "Unable to save dedicated\n" + er.Message + "\n" + er.StackTrace);
            }
        }
Ejemplo n.º 5
0
        //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());
            }
        }
Ejemplo n.º 6
0
        void commonConstructor()
        {
            //Launch XmlRpcClient---------------------------------------------------------------------------------
            Lama.log("NOTICE", "XmlRpcConnect");
            connectXmlRpc();
            Lama.loadForm.Close();

            if (Lama.connected)
            {
                Lama.log("NOTICE", "XmlRPC : Connected");

                //Affichage
                this.b_serverStarted.Enabled = false;
                this.b_xmlrpcConnect.Enabled = false;
                this.b_uasecoStop.Enabled    = false;
                this.b_usaecoStart.Enabled   = false;

                //Requêtes
                startupRequests();

                Lama.log("NOTICE", "Init inGamePlugins ...");
                //Init plugins
                if (!Lama.remote)
                {
                    List <InGamePlugin> removeLST = new List <InGamePlugin>();
                    foreach (InGamePlugin plug in Lama.inGamePlugins)
                    {
                        bool       badRequirement = false;
                        string     brInfos        = "";
                        LamaConfig conf2plug      = new LamaConfig()
                        {
                            connected   = true,
                            scriptName  = "",
                            remote      = Lama.remote,
                            configFiles = new Dictionary <string, XmlDocument>()
                        };
                        foreach (Requirement r in plug.Requirements)
                        {
                            switch (r.Type)
                            {
                            case RequirementType.PLUGIN:
                                if (getPluginByName(r.Value) == null)
                                {
                                    badRequirement = true;
                                    brInfos        = "Requiredplugin '" + r.Value + "does not exists";
                                }

                                break;

                            case RequirementType.FILE:
                                try
                                {
                                    conf2plug.configFiles.Add(r.Value, new XmlDocument(@"Config\Servers\" + Lama.serverIndex + @"\" + r.Value));
                                }
                                catch (Exception)
                                {
                                    badRequirement = true;
                                    brInfos        = @"Unable to load Config\Servers\" + Lama.serverIndex + @"\" + r.Value;
                                }
                                break;

                            case RequirementType.DATABASE:
                                conf2plug.dbConnected = false;
                                break;
                            }
                        }
                        if (!badRequirement)
                        {
                            badRequirement = !plug.onLoad(conf2plug);
                            brInfos        = "onLoad method returned false";
                        }

                        if (badRequirement)
                        {
                            Lama.log("ERROR", "Unable to init [" + plug.PluginName + "] Plugin, " + brInfos);
                            removeLST.Add(plug);
                        }
                        else
                        {
                            Lama.log("NOTICE", "[" + plug.PluginName + "] Plugin loaded");
                        }
                    }
                    foreach (InGamePlugin plug in removeLST)
                    {
                        Lama.inGamePlugins.Remove(plug);
                    }
                }
            }
            else
            {
                if (Lama.launched)
                {
                    Lama.onError(this, "Unable to connect", "Unable to connect to " + this.adrs + ":" + this.port + "\nPlease check server and/or Lama configuration");
                    this.Close();
                }
                else
                {
                    Lama.onError(this, "Server exited", "Server exited \nPlease check server logs and configuration");
                    this.Close();
                }
            }
        }