コード例 #1
0
 public ServerStat ToServerStat(ServerStat temp)
 {
     temp.GameType = this.GameType;
     temp.Map      = this.Map;
     temp.Mode     = this.Mode;
     return(temp);
 }
コード例 #2
0
        public static ServerStat GetServerStat(string json_string)
        {
            ServerStat temp = new ServerStat();

            try
            {
                //string json_string = File.ReadAllText(SAPPRemote.MainWindow.SettingPath);
                if (Json.IsValid(json_string))
                {
                    var s = new JsonSerializerSettings
                    {
                        NullValueHandling      = NullValueHandling.Ignore,
                        ObjectCreationHandling = ObjectCreationHandling.Replace // without this, you end up with duplicates.
                    };

                    temp = JsonConvert.DeserializeObject <ServerStat>(json_string, s);
                }
                else
                {
                }
            }
            catch (Exception)
            {
            }
            return(temp);
        }
コード例 #3
0
        public static void Msg(string temp)
        {
            switch (Json.Get_rco(temp))
            {
            case Server.RemoteConsoleOpcode.RC_LOGIN:
            {
                iSAPPRemoteUI.SetTitle(" > Online");
                Action append = () =>
                {
                    Paragraph p1 = new Paragraph();
                    p1.Append("Connected to the server.", Brushes.Transparent, Brushes.Green, true, false, false);

                    if (appJustStarted == true)
                    {
                        iSAPPRemoteUI.richtextBox_console.SetText(p1);
                        appJustStarted = false;
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    }

                    Paragraph p2 = new Paragraph();

                    p2.Append("Logged in, admin level: ", Brushes.Transparent, Brushes.Yellow, true, false, false);
                    p2.Append(Json.Get_str(temp, "level"), Brushes.Transparent, Brushes.Red, true, false, false);

                    iSAPPRemoteUI.richtextBox_console.CheckAppendText(p2);
                };

                if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                {
                    append();
                }
                else
                {
                    iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                }

                loadplayerslist = true;
                SendQUERY();
            }
                return;

            case Server.RemoteConsoleOpcode.RC_QUERY:
            {
                SS = Json.GetServerStat(temp);

                iSAPPRemoteUI.textblock_serverstat.SetText(SS.ToString());
                LoadPlayersStat(SS.Players);
            }
                return;

            case Server.RemoteConsoleOpcode.RC_QUERY_STATS:
            {
                PSS = Json.GetPlayersStat(temp);
                LoadPlayersStat(PSS.Players);
            }
                return;

            case Server.RemoteConsoleOpcode.RC_CIN:
            {
            }
                return;

            case Server.RemoteConsoleOpcode.RC_COUT:
            {
                Action append = () =>
                {
                    Paragraph p1 = new Paragraph();
                    p1.Append(Json.Get_str(temp, "text"), Brushes.Transparent, Brushes.Cyan, true, false, false);

                    iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                };

                if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                {
                    append();
                }
                else
                {
                    iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                }
            }
                return;

            case Server.RemoteConsoleOpcode.RC_CHAT:
            {
                PlayerData PD = iSAPPRemoteUI.playerslist.ToList()[Player.GetListIndex(iSAPPRemoteUI.playerslist.ToList(), Json.Get_int(temp, "index"))];

                switch (Json.Get_int(temp, "type"))
                {
                case 0:             //All
                {
                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("[GLOBAL] ", Brushes.Transparent, Brushes.LimeGreen, true, false, false);
                        p1.Append(PD.Name + ": ", Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(Json.Get_str(temp, "message"), Brushes.Transparent, Brushes.White, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                }
                    return;

                case 1:             //Team
                {
                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("[TEAM] ", Brushes.Transparent, Brushes.Yellow, true, false, false);
                        p1.Append(PD.Name + ": ", Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(Json.Get_str(temp, "message"), Brushes.Transparent, Brushes.White, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                }
                    return;

                case 2:             //Vehicle
                {
                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("[VEHICLE] ", Brushes.Transparent, Brushes.Blue, true, false, false);
                        p1.Append(PD.Name + ": ", Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(Json.Get_str(temp, "message"), Brushes.Transparent, Brushes.White, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                }
                    return;

                default:
                {
                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("[OTHER] ", Brushes.Transparent, Brushes.LimeGreen, true, false, false);
                        p1.Append(PD.Name + ": ", Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(Json.Get_str(temp, "message"), Brushes.Transparent, Brushes.White, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                }
                    return;
                }
            }

            case Server.RemoteConsoleOpcode.RC_PJOIN:
            {
                try
                {
                    iSAPPRemoteUI.updater.Stop();
                    PlayerData tempplayer = Player.GetData(temp);

                    if (!iSAPPRemoteUI.playerslist.ToList().Contains(tempplayer))
                    {
                        // tempplayer.CM = iSAPPRemoteUI.CM;

                        iSAPPRemoteUI.playerslist.Add(tempplayer);
                    }

                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("Player Joined, Name: ", Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(tempplayer.Name, Brushes.Transparent, Brushes.Green, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                    iSAPPRemoteUI.updater.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, ex.Message);
                }
            }
                return;

            case Server.RemoteConsoleOpcode.RC_PLEAVE:
            {
                try
                {
                    iSAPPRemoteUI.updater.Stop();
                    int        pindex = Player.GetListIndex(iSAPPRemoteUI.playerslist.ToList(), Json.Get_int(temp, "index"));
                    PlayerData PD     = iSAPPRemoteUI.playerslist[pindex];
                    iSAPPRemoteUI.playerslist.RemoveAt(pindex);

                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("Player Quit, Name: ", Brushes.Transparent, Brushes.Red, true, false, false);
                        p1.Append(PD.Name, Brushes.Transparent, Brushes.Green, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                    iSAPPRemoteUI.updater.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, ex.Message);
                }
            }
                return;

            case Server.RemoteConsoleOpcode.RC_TEAMCHANGE:
            {
                try
                {
                    iSAPPRemoteUI.updater.Stop();
                    TeamChange TC     = Json.GetTeamChange(temp);
                    int        pindex = Player.GetListIndex(iSAPPRemoteUI.playerslist.ToList(), TC.Index);
                    PlayerData PD     = new PlayerData();
                    PD = iSAPPRemoteUI.playerslist[pindex];

                    iSAPPRemoteUI.playerslist.RemoveAt(pindex);

                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("Teamchange, ", Brushes.Transparent, Brushes.Cyan, true, false, false);
                        p1.Append(PD.Name, Brushes.Transparent, Brushes.Green, true, false, false);
                        p1.Append(" changed to the ", Brushes.Transparent, Brushes.Cyan, true, false, false);
                        p1.Append(Player.GetTeamText(TC.ITeam), Brushes.Transparent, Brushes.Yellow, true, false, false);
                        p1.Append(" team", Brushes.Transparent, Brushes.Cyan, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                    iSAPPRemoteUI.playerslist.Add(PD);

                    iSAPPRemoteUI.updater.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, ex.Message);
                }
            }
                return;

            case Server.RemoteConsoleOpcode.RC_NEWGAME:
            {
                try
                {
                    iSAPPRemoteUI.updater.Stop();
                    NG = Json.GetNewGame(temp);

                    Action append = () =>
                    {
                        Paragraph p1 = new Paragraph();
                        p1.Append("New game, ", Brushes.Transparent, Brushes.Cyan, true, false, false);
                        p1.Append(NG.ToString(), Brushes.Transparent, Brushes.Cyan, true, false, false);

                        iSAPPRemoteUI.richtextBox_console.CheckAppendText(p1);
                    };

                    if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                    {
                        append();
                    }
                    else
                    {
                        iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append);
                    }
                    foreach (PlayerData PD in iSAPPRemoteUI.playerslist.ToList())
                    {
                        Action append2 = () =>
                        {
                            Paragraph p2 = new Paragraph();
                            p2.Append("Player Quit, Name: ", Brushes.Transparent, Brushes.Red, true, false, false);
                            p2.Append(PD.Name, Brushes.Transparent, Brushes.Green, true, false, false);

                            iSAPPRemoteUI.richtextBox_console.CheckAppendText(p2);
                        };

                        if (iSAPPRemoteUI.richtextBox_console.CheckAccess())
                        {
                            append2();
                        }
                        else
                        {
                            iSAPPRemoteUI.richtextBox_console.Dispatcher.BeginInvoke(append2);
                        }
                    }
                    iSAPPRemoteUI.playerslist.Clear();
                    SS = NG.ToServerStat(SS);
                    iSAPPRemoteUI.textblock_serverstat.SetText(SS.ToString());
                    iSAPPRemoteUI.updater.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, ex.Message);
                }
            }
                return;
            }
        }