public DevBehavior(DevClient client) { Client = client; Chat = client.ChatClient; m_packets = new Dictionary <DevClientPacket, Action <string> >(); RegisterPackets(); }
public void Run() { ChatClient = new DevConnection(Server.Address, Server.ChatPort); ChatClient.Send(DevServerPacket.Login, GetJsonLoginString()); m_gameClients = new List <GameClient>(); m_addedClients = new List <GameClient>(); m_removedClients = new List <GameClient>(); m_behavior = new DevBehavior(this); while (ChatClient.IsConnected) { while (ChatClient.HasPacket()) { DevPacket packet = ChatClient.Receive(); HandlePacket(packet); } foreach (GameClient game in m_gameClients) { #if !DEBUG try { game.Tick(); } catch (Exception ex) { game.Connection.Close(); File.WriteAllText("game_" + DateTime.UtcNow.ToString("dd-MM-yyyy-hh-mm-ss") + ".log", ex.ToString()); } #else game.Tick(); #endif } foreach (GameClient game in m_addedClients) { m_gameClients.Add(game); } m_addedClients.Clear(); foreach (GameClient game in m_removedClients) { m_gameClients.Remove(game); } m_removedClients.Clear(); if (HostEnabled) { for (int i = 0; i < m_infClient.Length; ++i) { if (m_infClient[i] == null || !m_gameClients.Contains(m_infClient[i])) { Thread.Sleep(500); ServerInfo server = GetServer(); if (server != null) { m_infClient[i] = new GameClient(this, server, GetRandomDuelName(false)); m_infClient[i].Start(); m_gameClients.Add(m_infClient[i]); } else { HostEnabled = false; } break; } } } if ((DateTime.Now - m_latestfix).TotalSeconds > 30) { ChatClient.Send(DevServerPacket.RefuseDuel); m_latestfix = DateTime.Now; } Thread.Sleep(1); } }