Index: src/drive_lfss/command_console/command.cs =================================================================== --- src/drive_lfss/command_console/command.cs (revision 29) +++ src/drive_lfss/command_console/command.cs (working copy) @@ -33,7 +33,8 @@ switch (args[0]) { - case "announce": Announce(args[1]); break; + case "status": Status(args[1]); break; + case "say": Say(args[1]); break; case "exit": Exit(); break; default: { @@ -42,13 +43,36 @@ } } } - private static void Announce(string _commandText) + private static void Status(string _commandText) { + if (_commandText == "*") + { + foreach (KeyValuePair keyPair in SessionList.sessionList) + Program.log.normal("Server ID : " + keyPair.Key + ", Status : " + (SessionList.sessionList[keyPair.Key].session.IsSocketStatus(Drive_LFSS.Definition_.InSim_Socket_State.INSIM_SOCKET_CONNECTED) ? " online, latency : " + SessionList.sessionList[keyPair.Key].session.GetLatency() + "ms" + ", Drivers connected : " + SessionList.sessionList[keyPair.Key].session.GetNbrOfDrivers() + "\r\n" : " offline\r\n")); + } + else + { + ushort serverId; + try { serverId = Convert.ToUInt16(_commandText); } + catch (Exception _exception) + { + Program.log.normal("Command Status, Syntax Error.\r\n Usage:\r\n status #serverId\r\n"); + return; + } + + if (SessionList.sessionList.ContainsKey(serverId)) + Program.log.normal("Server ID : " + serverId + ", Status : " + (SessionList.sessionList[serverId].session.IsSocketStatus(Drive_LFSS.Definition_.InSim_Socket_State.INSIM_SOCKET_CONNECTED) ? " online, latency : " + SessionList.sessionList[serverId].session.GetLatency() + "ms" + ", Drivers connected : " + SessionList.sessionList[serverId].session.GetNbrOfDrivers() + "\r\n" : " offline\r\n")); + else + Program.log.command("Command Status, ServerId Not Found, Server Requested was: " + serverId + "\r\n"); + } + } + private static void Say(string _commandText) + { string[] args = _commandText.Split(new string[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries); if (args.Length != 2) { - Program.log.normal("Command Announce, Syntax Error.\r\n Usage:\r\n announce #serverId $Message\r\n"); + Program.log.normal("Command Say, Syntax Error.\r\n Usage:\r\n say #serverId $Message\r\n"); return; } Index: src/game/session.cs =================================================================== --- src/game/session.cs (revision 29) +++ src/game/session.cs (working copy) @@ -40,11 +40,26 @@ } private char commandPrefix; + private long pingTime; + private long sessionLatency; + private const uint TIMER_PING_PONG = 30000; + private uint TimerPingPong = 0; + private Race race; private List driverList; new public void update(uint diff) { + if (TIMER_PING_PONG < (TimerPingPong += diff)) + { + log.ping("Ping!\r\n"); + + AddToTcpSendingQueud(new Packet(Packet_Size.PACKET_SIZE_TINY, Packet_Type.PACKET_TINY_MULTI_PURPOSE, new PacketTiny(1, Tiny_Type.TINY_PING))); + pingTime = DateTime.Now.Ticks; + + TimerPingPong = 0; + } + base.update(diff); foreach (Driver _driver in driverList) _driver.update(diff); @@ -179,6 +194,15 @@ //Can receive some info about the Car that triggered this State Change... //TODO: Add this Init into Driver If carId is Found into STA. } + protected sealed override void processPacket(PacketTiny _packet) + { + base.processPacket(_packet); + switch (_packet.subTinyType) + { + case Tiny_Type.TINY_PING: ReceivePong(); break; + default: Program.log.normal("session.cs, processPacket(PacketTiny _packet) - Missing case " + _packet.subTinyType); break; + } + } #region Driver/Car/Licence Association Tool private byte GetCarIndex(byte _carId) @@ -230,6 +254,18 @@ } return false; } + private void ReceivePong() + { + sessionLatency = (DateTime.Now.Ticks - pingTime) / 10000; + } + public int GetNbrOfDrivers() + { + return driverList.Count - 1; + } + public long GetLatency() + { + return sessionLatency; + } #endregion } } Index: src/network/insim/insim.cs =================================================================== --- src/network/insim/insim.cs (revision 29) +++ src/network/insim/insim.cs (working copy) @@ -235,6 +235,11 @@ ((Server)this).log.network("UdpReceive(), PacketSize->" + packetSize + ", PacketType->" + (Packet_Type)data[1] + "\r\n"); AddToUdpReceiveQueud(new Packet(data)); } + + public InSim_Socket_State GetSocketStatus() + { + return socketStatus; + } } //This class is non sence, is keeped cause of Time related question Index: src/server/server.cs =================================================================== --- src/server/server.cs (revision 29) +++ src/server/server.cs (working copy) @@ -40,27 +40,13 @@ { get { return serverId; } } - private long pingTime; public sLog log; private CommandServer command; #region update - - private const uint TIMER_PING_PONG = 30000; - private uint TimerPingPong = 0; public void update(uint diff) //update called By Session { - if (TIMER_PING_PONG < (TimerPingPong += diff)) - { - log.debug("Request Ping!\r\n"); - - AddToTcpSendingQueud(new Packet( Packet_Size.PACKET_SIZE_TINY, Packet_Type.PACKET_TINY_MULTI_PURPOSE, new PacketTiny(1, Tiny_Type.TINY_PING)) ); - pingTime = DateTime.Now.Ticks; - - TimerPingPong = 0; - } - object[] _nextTcpPacket = NextTcpReceiveQueud(true); if (_nextTcpPacket != null) ProcessPacket((Packet_Type)_nextTcpPacket[0], _nextTcpPacket[1]);