Ejemplo n.º 1
0
        public async void RefreshAdminList()
        {
            log.Trace("RefreshAdminList(): Start");
            var qi = new RconQueueItem("bf2cc getadminlist", RconClient.RconState.AsyncCommand);

            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;

            AdminList.Clear();
            foreach (var line in lines)
            {
                var admins = reg_Admin.Match(line);
                if (admins.Success)
                {
                    var name = admins.Groups["name"].Value;
                    var ip   = admins.Groups["ip"].Value;
                    var port = int.Parse(admins.Groups["port"].Value);
                    Debug.WriteLine("Admin: " + name + " -> " + ip + ":" + port);
                    AdminList.Add(new AdminListItem()
                    {
                        Name = name, Address = ip, Port = port
                    });
                }
            }
            log.Trace("RefreshAdminList(): End (" + lines.Count + " admins)");
        }
Ejemplo n.º 2
0
 public async Task<List<string>> Exec(string command)
 {
     log.Trace("SimpleCommand: Start exec: \"" + command + "\"");
     var qi = new RconQueueItem(command, RconClient.RconState.AsyncCommand);
     RconClient.EnqueueCommand(qi);
     var ret = await qi.TaskCompletionSource.Task;
     log.Trace("SimpleCommand: End exec: \"" + command + "\" (" + ret.Count + " lines)");
     OnCommandDone(command, ret);
     return ret;
 }
        public async void RefreshClientChatBufferCommand()
        {
            log.Trace("RefreshClientChatBufferCommand(): Start");
            var qi = new RconQueueItem("bf2cc clientchatbuffer", RconClient.RconState.AsyncCommand);
            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;
            
            foreach (var line in lines)
            {
                var clientBuffer = reg_ClientBuffer.Match(line);
                if (clientBuffer.Success)
                {
                    var number = clientBuffer.Groups["number"].Value;
                    var from = clientBuffer.Groups["from"].Value;
                    var what = clientBuffer.Groups["what"].Value;
                    var type = clientBuffer.Groups["type"].Value;
                    var timestamp = clientBuffer.Groups["timestamp"].Value;
                    var message = clientBuffer.Groups["message"].Value;
                    Debug.WriteLine(timestamp + " <" + from + "> " + message);
                    var item = new ChatHistoryItem()
                                   {
                                       Number = int.Parse(number),
                                       From = from,
                                       What = what,
                                       Type = type,
                                       TimeStamp = timestamp,
                                       Message = message
                                   };
                    lock (ChatHistory)
                    {
                        ChatHistory.Add(item);
                        while (ChatHistory.Count > ChatHistorySize)
                        {
                            ChatHistory.RemoveAt(0);
                        }
                    }
                    OnChatLineReceived(item);

                    // Now check if its a command
                    var result = reg_Command.Match(item.Message);
                    if (result.Success)
                    {
                        var cmd = result.Groups["cmd"].Value.ToLower();
                        var p = result.Groups["params"].Value;
                        p = Regex.Replace(p, @"\s\s+", " ");
                        var ps = p.Split(c_space);
                        OnCommandReceived(item, item.From, cmd, ps, p);
                    }
                        

                }
            }
            log.Trace("RefreshClientChatBufferCommand(): End (" + lines.Count + " chat lines)");

        }
Ejemplo n.º 4
0
        public async Task <List <string> > Exec(string command)
        {
            log.Trace("SimpleCommand: Start exec: \"" + command + "\"");
            var qi = new RconQueueItem(command, RconClient.RconState.AsyncCommand);

            RconClient.EnqueueCommand(qi);
            var ret = await qi.TaskCompletionSource.Task;

            log.Trace("SimpleCommand: End exec: \"" + command + "\" (" + ret.Count + " lines)");
            OnCommandDone(command, ret);
            return(ret);
        }
Ejemplo n.º 5
0
        public async void RefreshClientChatBufferCommand()
        {
            log.Trace("RefreshClientChatBufferCommand(): Start");
            var qi = new RconQueueItem("bf2cc clientchatbuffer", RconClient.RconState.AsyncCommand);

            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;

            foreach (var line in lines)
            {
                var clientBuffer = reg_ClientBuffer.Match(line);
                if (clientBuffer.Success)
                {
                    var number    = clientBuffer.Groups["number"].Value;
                    var from      = clientBuffer.Groups["from"].Value;
                    var what      = clientBuffer.Groups["what"].Value;
                    var type      = clientBuffer.Groups["type"].Value;
                    var timestamp = clientBuffer.Groups["timestamp"].Value;
                    var message   = clientBuffer.Groups["message"].Value;
                    Debug.WriteLine(timestamp + " <" + from + "> " + message);
                    var item = new ChatHistoryItem()
                    {
                        Number    = int.Parse(number),
                        From      = from,
                        What      = what,
                        Type      = type,
                        TimeStamp = timestamp,
                        Message   = message
                    };
                    lock (ChatHistory)
                    {
                        ChatHistory.Add(item);
                        while (ChatHistory.Count > ChatHistorySize)
                        {
                            ChatHistory.RemoveAt(0);
                        }
                    }
                    OnChatLineReceived(item);

                    // Now check if its a command
                    var result = reg_Command.Match(item.Message);
                    if (result.Success)
                    {
                        var cmd = result.Groups["cmd"].Value.ToLower();
                        var p   = result.Groups["params"].Value;
                        p = Regex.Replace(p, @"\s\s+", " ");
                        var ps = p.Split(c_space);
                        OnCommandReceived(item, item.From, cmd, ps, p);
                    }
                }
            }
            log.Trace("RefreshClientChatBufferCommand(): End (" + lines.Count + " chat lines)");
        }
Ejemplo n.º 6
0
        public async void RefreshAdminList()
        {
            log.Trace("RefreshAdminList(): Start");
            var qi = new RconQueueItem("bf2cc getadminlist", RconClient.RconState.AsyncCommand);
            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;

            AdminList.Clear();
            foreach (var line in lines)
            {
                var admins = reg_Admin.Match(line);
                if (admins.Success)
                {
                    var name = admins.Groups["name"].Value;
                    var ip = admins.Groups["ip"].Value;
                    var port = int.Parse(admins.Groups["port"].Value);
                    Debug.WriteLine("Admin: " + name + " -> " + ip + ":" + port);
                    AdminList.Add(new AdminListItem() { Name=name, Address=ip, Port=port});
                }
            }
            log.Trace("RefreshAdminList(): End (" + lines.Count + " admins)");
        }
Ejemplo n.º 7
0
        public async void RefreshServerInfo()
        {
            log.Trace("RefreshServerInfo(): Start");
            var qi = new RconQueueItem("bf2cc si", RconClient.RconState.AsyncCommand);

            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;

            foreach (var line in lines)
            {
                //var serverInfo = reg_ServerInfo.Match(line);
                //if (serverInfo.Success)
                //{
                var siSplit = line.Split(Utils.Tab);
                log.Trace("RefreshServerInfo(): Server info for: " + siSplit[7]);
                // 7.2	1	16	0	0	lake	seaside_skirmish	Konge.net Battlefield Heroes Server	National	0	3	3	0	British	0	3	3	0	10	-1	gpm_ctf	bfheroes	(1024, 1024)	0	0	1	0	0	14699.5590077	0	3	1
                ServerInfo.Version            = siSplit[0];
                ServerInfo.CurrentGameStatus  = (ServerInfo.GameStatus)Enum.Parse(typeof(ServerInfo.GameStatus), siSplit[1]);
                ServerInfo.MaxPlayers         = int.Parse(siSplit[2]);
                ServerInfo.Players            = int.Parse(siSplit[3]);
                ServerInfo.Joining            = int.Parse(siSplit[4]);
                ServerInfo.MapName            = siSplit[5];
                ServerInfo.MapInfo            = RconClient.GetMapInfoFromName(siSplit[5]);
                ServerInfo.NextMapName        = siSplit[6];
                ServerInfo.NextMapInfo        = RconClient.GetMapInfoFromName(siSplit[6]);
                ServerInfo.ServerName         = siSplit[7];
                ServerInfo.Team1.Name         = siSplit[8];
                ServerInfo.Team1.TicketState  = int.Parse(siSplit[9]);
                ServerInfo.Team1.StartTickets = int.Parse(siSplit[10]);
                ServerInfo.Team1.Tickets      = int.Parse(siSplit[11]);
                ServerInfo.Unknown0           = siSplit[12];
                ServerInfo.Team2.Name         = siSplit[13];
                ServerInfo.Team2.TicketState  = int.Parse(siSplit[14]);
                ServerInfo.Team2.StartTickets = int.Parse(siSplit[15]);
                ServerInfo.Team2.Tickets      = int.Parse(siSplit[16]);
                ServerInfo.Unknown1           = siSplit[17];
                ServerInfo.ElapsedRoundTime   = int.Parse(siSplit[18]);
                ServerInfo.RemainingTime      = int.Parse(siSplit[19]);
                ServerInfo.GameMode           = siSplit[20];
                ServerInfo.GameModeType       = (ServerInfo.GameType)Enum.Parse(typeof(ServerInfo.GameType), siSplit[20]);
                ServerInfo.ModDir             = siSplit[21];
                ServerInfo.WorldSize          = siSplit[22];
                ServerInfo.TimeLimit          = int.Parse(siSplit[23]);
                ServerInfo.AutoBalance        = Utils.BoolParse(siSplit[24]);
                ServerInfo.RankedStatus       = Utils.BoolParse(siSplit[25]);
                ServerInfo.Team1.Count        = int.Parse(siSplit[26]);
                ServerInfo.Team2.Count        = int.Parse(siSplit[27]);
                ServerInfo.WallTime           = decimal.Parse(siSplit[28], NumberStyles.Float, CultureInfo.InvariantCulture);
                ServerInfo.ReservedSlots      = int.Parse(siSplit[29]);
                ServerInfo.TotalRounds        = int.Parse(siSplit[30]);
                ServerInfo.CurrentRound       = int.Parse(siSplit[31]);

                ServerInfo.IsPregame = !(ServerInfo.Team1.Count > 1 && ServerInfo.Team2.Count > 1);

                OnServerInfoUpdated(ServerInfo);

                // Round ends when:
                // gpm_tdm  - Team tickets reach 0
                // gpm_ctf  - Team tickets reach 0
                // gpm_hoth - Team tickets reach 0

                if (_lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                {
                    // Round time has decreased, new round
                }
                if (ServerInfo.CurrentGameStatus != ServerInfo.GameStatus.EndScreen && ServerInfo.Team1.Tickets > 0 && ServerInfo.Team2.Tickets > 0)
                {
                    if (!_inRound && _lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                    {
                        // Round starting (and we have seen a previous round)
                        OnRoundStart(_lastRoundServerInfo);
                    }
                    _inRound = true;
                }
                else
                {
                    if (_inRound)
                    {
                        // Round done
                        OnRoundEnd(_lastRoundServerInfo);
                    }
                    _inRound = false;
                }

                //if (_lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                if (_lastElapsedRoundTime > ServerInfo.ElapsedRoundTime || (_lastRoundServerInfo != null && ServerInfo.CurrentGameStatus != _lastRoundServerInfo.CurrentGameStatus))
                {
                    switch (ServerInfo.CurrentGameStatus)
                    {
                    case ServerInfo.GameStatus.Running:
//                            OnRoundStart(_lastRoundServerInfo);
                        break;

                    case ServerInfo.GameStatus.EndScreen:
                        // Doesn't work
                        break;
                    }
                }
                _lastElapsedRoundTime = ServerInfo.ElapsedRoundTime;
                //}
                log.Trace("RefreshServerInfo(): End");
            }
        }
Ejemplo n.º 8
0
        public async void RefreshPlayerList()
        {
            log.Trace("RefreshPlayerList(): Start");
            var qi = new RconQueueItem("bf2cc pl", RconClient.RconState.AsyncCommand);
            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;
            int added = 0, removed = 0;
            DateTime updateTimestamp = DateTime.Now;
            // Process result
            OnPlayerUpdateStart();
            var _plPlayerDiff = new Dictionary<Player, bool>();
            foreach (var line in lines)
            {

                var plSplit = line.Split(Utils.Tab);
                var playerName = plSplit[1];
                //Debug.WriteLine("Player info for: " + playerName);
                Player p = GetPlayer(plSplit[1]);
                bool newPlayer = false;
                if (p == null)
                {
                    newPlayer = true;
                    p = new Player();
                    lock (_players)
                    {
                        _players.Add(playerName, p);
                        added++;
                    }
                }
                _plPlayerDiff.Add(p, true);
                p.Index = plSplit[0];
                p.Name = plSplit[1];
                p.TeamId = int.Parse(plSplit[2]);
                // Link to correct team object
                if (p.TeamId == 1)
                    p.Team = RconClient.ServerInfoCommand.ServerInfo.Team1;
                if (p.TeamId == 2)
                    p.Team = RconClient.ServerInfoCommand.ServerInfo.Team2;

                p.Ping = int.Parse(plSplit[3]);
                p.IsConnected = Utils.BoolParse(plSplit[4]);
                p.IsValid = Utils.BoolParse(plSplit[5]);
                p.IsRemote = Utils.BoolParse(plSplit[6]);
                p.IsAIPlayer = Utils.BoolParse(plSplit[7]);
                p.IsAlive = Utils.BoolParse(plSplit[8]);
                p.IsManDown = Utils.BoolParse(plSplit[9]);
                p.ProfileId = int.Parse(plSplit[10]);
                p.IsFlagholder = Utils.BoolParse(plSplit[11]);
                p.Suicide = int.Parse(plSplit[12]);
                p.TimeToSpawn = decimal.Parse(plSplit[13], NumberStyles.Float, CultureInfo.InvariantCulture);
                p.SquadId = int.Parse(plSplit[14]);
                p.IsSquadLeader = Utils.BoolParse(plSplit[15]);
                p.IsCommander = Utils.BoolParse(plSplit[16]);
                p.SpawnGroup = int.Parse(plSplit[17]);
                p.Address = plSplit[18];
                p.Score.DamageAssists = int.Parse(plSplit[19]);
                p.Score.PassengerAssists = int.Parse(plSplit[20]);
                p.Score.TargetAssists = int.Parse(plSplit[21]);
                p.Score.Revives = int.Parse(plSplit[22]);
                p.Score.TeamDamages = int.Parse(plSplit[23]);
                p.Score.TeamVehicleDamages = int.Parse(plSplit[24]);
                p.Score.CpCaptures = int.Parse(plSplit[25]);
                p.Score.CpDefends = int.Parse(plSplit[26]);
                p.Score.CpAssists = int.Parse(plSplit[27]);
                p.Score.CpNeutralizes = int.Parse(plSplit[28]);
                p.Score.CpNeutralizeAssists = int.Parse(plSplit[29]);
                p.Score.Suicides = int.Parse(plSplit[30]);
                p.Score.Kills = int.Parse(plSplit[31]);
                p.Score.TeamKills = int.Parse(plSplit[32]);
                p.VehicleType = int.Parse(plSplit[33]);
                p.Kit = plSplit[34]; //kit.templateName
                p.ConnectedAt = decimal.Parse(plSplit[35], NumberStyles.Float, CultureInfo.InvariantCulture);
                //ki.connectedAt
                p.Score.Deaths = int.Parse(plSplit[36]);
                p.Score.Score = int.Parse(plSplit[37]);
                p.VehicleName = plSplit[38];
                p.Score.Rank = int.Parse(plSplit[39]);
                p.PositionString = plSplit[40];
                p.IdleTime = int.Parse(plSplit[41]); //ki.idleTime
                p.Cdkeyhash = plSplit[42];
                p.TkData_Punished = Utils.BoolParse(plSplit[43]); //tkData.punished
                p.TkData_TimesPunished = int.Parse(plSplit[44]); //tkData.timesPunished
                p.TkData_TimesForgiven = int.Parse(plSplit[45]); //tkData.timesForgiven
                p.Vip = Utils.BoolParse(plSplit[46]);
                p.NucleusId = Int64.Parse(plSplit[47]);
                p.LastUpdate = updateTimestamp;
                if (newPlayer)
                {
                    RconClient.ServerInfoCommand.ServerInfo.Team1.AddPlayer(p);
                    OnPlayerJoined(p);
                }

                
            }

            foreach (var kvp in new Dictionary<string, Player>(_players))
            {
                if (!_plPlayerDiff.ContainsKey(kvp.Value))
                {
                    _players.Remove(kvp.Key);
                    RconClient.ServerInfoCommand.ServerInfo.Team1.RemovePlayer(kvp.Value);
                    OnPlayerLeft(kvp.Value);
                    removed++;
                }
                else
                {
                    // Signal that player has been updated
                    //OnPlayerUpdated(kvp.Value);
                }
            }

            OnPlayerUpdateDone();

            log.Trace("RefreshPlayerList(): End (" + lines.Count + " players, " + added + " new, " + removed + " removed)");

        }
Ejemplo n.º 9
0
        public async void RefreshServerInfo()
        {
            log.Trace("RefreshServerInfo(): Start");
            var qi = new RconQueueItem("bf2cc si", RconClient.RconState.AsyncCommand);
            RconClient.EnqueueCommand(qi);
            var lines = await qi.TaskCompletionSource.Task;

            foreach (var line in lines)
            {
                //var serverInfo = reg_ServerInfo.Match(line);
                //if (serverInfo.Success)
                //{
                var siSplit = line.Split(Utils.Tab);
                log.Trace("RefreshServerInfo(): Server info for: " + siSplit[7]);
                // 7.2	1	16	0	0	lake	seaside_skirmish	Konge.net Battlefield Heroes Server	National	0	3	3	0	British	0	3	3	0	10	-1	gpm_ctf	bfheroes	(1024, 1024)	0	0	1	0	0	14699.5590077	0	3	1
                ServerInfo.Version = siSplit[0];
                ServerInfo.CurrentGameStatus = (ServerInfo.GameStatus)Enum.Parse(typeof(ServerInfo.GameStatus), siSplit[1]);
                ServerInfo.MaxPlayers = int.Parse(siSplit[2]);
                ServerInfo.Players = int.Parse(siSplit[3]);
                ServerInfo.Joining = int.Parse(siSplit[4]);
                ServerInfo.MapName = siSplit[5];
                ServerInfo.MapInfo = RconClient.GetMapInfoFromName(siSplit[5]);
                ServerInfo.NextMapName = siSplit[6];
                ServerInfo.NextMapInfo = RconClient.GetMapInfoFromName(siSplit[6]);
                ServerInfo.ServerName = siSplit[7];
                ServerInfo.Team1.Name = siSplit[8];
                ServerInfo.Team1.TicketState = int.Parse(siSplit[9]);
                ServerInfo.Team1.StartTickets = int.Parse(siSplit[10]);
                ServerInfo.Team1.Tickets = int.Parse(siSplit[11]);
                ServerInfo.Unknown0 = siSplit[12];
                ServerInfo.Team2.Name = siSplit[13];
                ServerInfo.Team2.TicketState = int.Parse(siSplit[14]);
                ServerInfo.Team2.StartTickets = int.Parse(siSplit[15]);
                ServerInfo.Team2.Tickets = int.Parse(siSplit[16]);
                ServerInfo.Unknown1 = siSplit[17];
                ServerInfo.ElapsedRoundTime = int.Parse(siSplit[18]);
                ServerInfo.RemainingTime = int.Parse(siSplit[19]);
                ServerInfo.GameMode = siSplit[20];
                ServerInfo.GameModeType = (ServerInfo.GameType)Enum.Parse(typeof(ServerInfo.GameType), siSplit[20]);
                ServerInfo.ModDir = siSplit[21];
                ServerInfo.WorldSize = siSplit[22];
                ServerInfo.TimeLimit = int.Parse(siSplit[23]);
                ServerInfo.AutoBalance = Utils.BoolParse(siSplit[24]);
                ServerInfo.RankedStatus = Utils.BoolParse(siSplit[25]);
                ServerInfo.Team1.Count = int.Parse(siSplit[26]);
                ServerInfo.Team2.Count = int.Parse(siSplit[27]);
                ServerInfo.WallTime = decimal.Parse(siSplit[28], NumberStyles.Float, CultureInfo.InvariantCulture);
                ServerInfo.ReservedSlots = int.Parse(siSplit[29]);
                ServerInfo.TotalRounds = int.Parse(siSplit[30]);
                ServerInfo.CurrentRound = int.Parse(siSplit[31]);

                ServerInfo.IsPregame = !(ServerInfo.Team1.Count > 1 && ServerInfo.Team2.Count > 1);

                OnServerInfoUpdated(ServerInfo);

                // Round ends when:
                // gpm_tdm  - Team tickets reach 0
                // gpm_ctf  - Team tickets reach 0
                // gpm_hoth - Team tickets reach 0

                if (_lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                {
                    // Round time has decreased, new round
                }
                if (ServerInfo.CurrentGameStatus != ServerInfo.GameStatus.EndScreen && ServerInfo.Team1.Tickets > 0 && ServerInfo.Team2.Tickets > 0)
                {
                    if (!_inRound && _lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                    {
                        // Round starting (and we have seen a previous round)
                        OnRoundStart(_lastRoundServerInfo);
                    }
                    _inRound = true;
                }
                else
                {
                    if (_inRound)
                    {
                        // Round done
                        OnRoundEnd(_lastRoundServerInfo);
                    }
                    _inRound = false;
                }

                //if (_lastElapsedRoundTime > ServerInfo.ElapsedRoundTime)
                if (_lastElapsedRoundTime>ServerInfo.ElapsedRoundTime || (_lastRoundServerInfo != null && ServerInfo.CurrentGameStatus != _lastRoundServerInfo.CurrentGameStatus))
                {
                    switch (ServerInfo.CurrentGameStatus)
                    {
                        case ServerInfo.GameStatus.Running:
//                            OnRoundStart(_lastRoundServerInfo);
                            break;
                        case ServerInfo.GameStatus.EndScreen:
                            // Doesn't work
                            break;
                    }

                }
                _lastElapsedRoundTime = ServerInfo.ElapsedRoundTime;
                //}
                log.Trace("RefreshServerInfo(): End");
            }
        }
Ejemplo n.º 10
0
        public async void RefreshPlayerList()
        {
            log.Trace("RefreshPlayerList(): Start");
            var qi = new RconQueueItem("bf2cc pl", RconClient.RconState.AsyncCommand);

            RconClient.EnqueueCommand(qi);
            var      lines = await qi.TaskCompletionSource.Task;
            int      added = 0, removed = 0;
            DateTime updateTimestamp = DateTime.Now;

            // Process result
            OnPlayerUpdateStart();
            var _plPlayerDiff = new Dictionary <Player, bool>();

            foreach (var line in lines)
            {
                var plSplit    = line.Split(Utils.Tab);
                var playerName = plSplit[1];
                //Debug.WriteLine("Player info for: " + playerName);
                Player p         = GetPlayer(plSplit[1]);
                bool   newPlayer = false;
                if (p == null)
                {
                    newPlayer = true;
                    p         = new Player();
                    lock (_players)
                    {
                        _players.Add(playerName, p);
                        added++;
                    }
                }
                _plPlayerDiff.Add(p, true);
                p.Index  = plSplit[0];
                p.Name   = plSplit[1];
                p.TeamId = int.Parse(plSplit[2]);
                // Link to correct team object
                if (p.TeamId == 1)
                {
                    p.Team = RconClient.ServerInfoCommand.ServerInfo.Team1;
                }
                if (p.TeamId == 2)
                {
                    p.Team = RconClient.ServerInfoCommand.ServerInfo.Team2;
                }

                p.Ping                      = int.Parse(plSplit[3]);
                p.IsConnected               = Utils.BoolParse(plSplit[4]);
                p.IsValid                   = Utils.BoolParse(plSplit[5]);
                p.IsRemote                  = Utils.BoolParse(plSplit[6]);
                p.IsAIPlayer                = Utils.BoolParse(plSplit[7]);
                p.IsAlive                   = Utils.BoolParse(plSplit[8]);
                p.IsManDown                 = Utils.BoolParse(plSplit[9]);
                p.ProfileId                 = int.Parse(plSplit[10]);
                p.IsFlagholder              = Utils.BoolParse(plSplit[11]);
                p.Suicide                   = int.Parse(plSplit[12]);
                p.TimeToSpawn               = decimal.Parse(plSplit[13], NumberStyles.Float, CultureInfo.InvariantCulture);
                p.SquadId                   = int.Parse(plSplit[14]);
                p.IsSquadLeader             = Utils.BoolParse(plSplit[15]);
                p.IsCommander               = Utils.BoolParse(plSplit[16]);
                p.SpawnGroup                = int.Parse(plSplit[17]);
                p.Address                   = plSplit[18];
                p.Score.DamageAssists       = int.Parse(plSplit[19]);
                p.Score.PassengerAssists    = int.Parse(plSplit[20]);
                p.Score.TargetAssists       = int.Parse(plSplit[21]);
                p.Score.Revives             = int.Parse(plSplit[22]);
                p.Score.TeamDamages         = int.Parse(plSplit[23]);
                p.Score.TeamVehicleDamages  = int.Parse(plSplit[24]);
                p.Score.CpCaptures          = int.Parse(plSplit[25]);
                p.Score.CpDefends           = int.Parse(plSplit[26]);
                p.Score.CpAssists           = int.Parse(plSplit[27]);
                p.Score.CpNeutralizes       = int.Parse(plSplit[28]);
                p.Score.CpNeutralizeAssists = int.Parse(plSplit[29]);
                p.Score.Suicides            = int.Parse(plSplit[30]);
                p.Score.Kills               = int.Parse(plSplit[31]);
                p.Score.TeamKills           = int.Parse(plSplit[32]);
                p.VehicleType               = int.Parse(plSplit[33]);
                p.Kit         = plSplit[34]; //kit.templateName
                p.ConnectedAt = decimal.Parse(plSplit[35], NumberStyles.Float, CultureInfo.InvariantCulture);
                //ki.connectedAt
                p.Score.Deaths         = int.Parse(plSplit[36]);
                p.Score.Score          = int.Parse(plSplit[37]);
                p.VehicleName          = plSplit[38];
                p.Score.Rank           = int.Parse(plSplit[39]);
                p.PositionString       = plSplit[40];
                p.IdleTime             = int.Parse(plSplit[41]);       //ki.idleTime
                p.Cdkeyhash            = plSplit[42];
                p.TkData_Punished      = Utils.BoolParse(plSplit[43]); //tkData.punished
                p.TkData_TimesPunished = int.Parse(plSplit[44]);       //tkData.timesPunished
                p.TkData_TimesForgiven = int.Parse(plSplit[45]);       //tkData.timesForgiven
                p.Vip        = Utils.BoolParse(plSplit[46]);
                p.NucleusId  = Int64.Parse(plSplit[47]);
                p.LastUpdate = updateTimestamp;
                if (newPlayer)
                {
                    RconClient.ServerInfoCommand.ServerInfo.Team1.AddPlayer(p);
                    OnPlayerJoined(p);
                }
            }

            foreach (var kvp in new Dictionary <string, Player>(_players))
            {
                if (!_plPlayerDiff.ContainsKey(kvp.Value))
                {
                    _players.Remove(kvp.Key);
                    RconClient.ServerInfoCommand.ServerInfo.Team1.RemovePlayer(kvp.Value);
                    OnPlayerLeft(kvp.Value);
                    removed++;
                }
                else
                {
                    // Signal that player has been updated
                    //OnPlayerUpdated(kvp.Value);
                }
            }

            OnPlayerUpdateDone();

            log.Trace("RefreshPlayerList(): End (" + lines.Count + " players, " + added + " new, " + removed + " removed)");
        }
Ejemplo n.º 11
0
 internal void EnqueueCommand(RconQueueItem rconQueueItem)
 {
     lock (CommandQueue)
     {
         log.Trace("EnqueueCommand(): " + rconQueueItem.Command);
         CommandQueue.Enqueue(rconQueueItem);
     }
 }
Ejemplo n.º 12
0
        private void ProcessLine(string line)
        {
            if (line == null)
                return;

            if (DebugProtocolData)
                log.Trace("ProcessLine(): " + line);

            OnReceivedLine(line);

            // Command completed?
            bool currentStateDone = line.Contains("unknown command: '" + _doneCommand + "'");

            switch (CurrentState)
            {
                #region Login/Auth
                case RconState.Login:
                    var greet = reg_Greet.Match(line);
                    if (greet.Success)
                    {
                        ServerVersion = greet.Groups[1].Value;
                        log.Debug("ProcessLine(): Server version: " + ServerVersion);
                    }
                    var seed = reg_Seed.Match(line);
                    if (seed.Success)
                    {
                        CurrentState = RconState.Auth;
                        var ret = "login " + HashString(seed.Groups[1].Value + Password);
                        log.Trace("ProcessLine(): Sending login info: " + ret);
                        Write(ret + "\n");
                        return;
                    }
                    break;
                case RconState.Auth:
                    if (line.StartsWith("Authentication failed"))
                    {
                        log.Error("Authentication failed!");
                        CurrentState = RconState.Unknown;
                        OnAuthFailed();
                        Disconnect();
                        return;
                    }
                    if (line.StartsWith("Authentication successful"))
                    {
                        log.Debug("ProcessLine(): Authentication successful. We are logged in.");
                        CurrentState = RconState.Ready;
                        OnConnected();
                        // Start polling
                        StartPollingTimers();
                        return;
                    }
                    break;
                #endregion
                case RconState.AsyncCommand:
                    if (CurrentCommand == null)
                        break;
                    if (CurrentStateWaitingForFirst)
                    {
                        CurrentStateWaitingForFirst = false;
                        _asyncCommandReturnBuffer = new List<string>();
                    }
                    if (currentStateDone)
                    {
                        var cc = CurrentCommand;
                        CurrentCommand = null;
                        // Special state - we need to free up for next command, return data to async waiting and completely exit (so we don't re-set CurrentState when new command has started)
                        CurrentState = RconState.Ready;
                        cc.TaskCompletionSource.SetResult(_asyncCommandReturnBuffer);
                        return;
                    }
                    _asyncCommandReturnBuffer.Add(line);
                    break;

                default:
                    log.Trace("ProcessLine(): Unhandled line: " + line);
                    OnReceivedUnhandledLine(line);
                    break;

            }


            if (currentStateDone)
                CurrentState = RconState.Ready;

        }
Ejemplo n.º 13
0
        private async void WriteLoop()
        {
            log.Trace("WriteLoop(): Start. Interval: " + SendDelayMs + " ms");
            while (true)
            {
                await Task.Delay(SendDelayMs);
                if (!_connected)
                    break;

                //// If a command uses too long to return we move on
                //if (CurrentState != RconState.Ready)
                //{
                //    if (DateTime.Now > CurrentStateTimeout)
                //        CurrentState = RconState.Ready;
                //}

                if (CurrentState == RconState.Ready)
                {
                    lock (CommandQueue)
                    {

                        if (CommandQueue.Count > 0)
                        {
                            var cmd = CommandQueue.Dequeue();
                            CurrentCommand = cmd;
                            CurrentState = cmd.PutsInState;
                            CurrentStateWaitingForFirst = true;
                            //CurrentStateTimeout = DateTime.Now.AddMilliseconds(DefaultCommandTimeoutMs);
                            log.Trace("WriteLoop(): Sending command: \"" + cmd.Command + "\"");
                            Write(cmd.Command + "\n" + "\x002" + _doneCommand + "\n");
                        }
                    }
                }
            }
            log.Trace("WriteLoop(): End");
        }