public KSObject RecvMessage() { var data = network.RecvData(); if (data == null || data.Length == 0) { return(null); } KSObject msg = parser.Decode(data); return(msg); }
private KSObject RecvMessage() { KSObject tmp = protocol.RecvMessage(); if (tmp != null) { return(tmp); } Logger.Log("Connection closed"); Quit(); Environment.Exit(0); return(null); }
public void SendCommandThread() { while (true) { KSObject msg = commandSendQueue.Take(); if (msg == null) { break; } if (gameRunning) { SendMessage(msg); } } }
public bool Join() { KSObject joinMessage; if (Config.GetInstance().Configuration.Value("general").Value <bool>("offline_mode")) { joinMessage = new JoinOfflineGame { TeamNickname = Config.GetInstance().Configuration.Value("ai").Value <string>("team_nickname"), AgentName = Config.GetInstance().Configuration.Value("ai").Value <string>("agent_name") }; } else { joinMessage = new JoinOnlineGame { Token = Config.GetInstance().Configuration.Value("ai").Value <string>("token"), AgentName = Config.GetInstance().Configuration.Value("ai").Value <string>("agent_name") }; } SendMessage(joinMessage); ClientJoined clientJoinedMessage; while (true) { KSObject tmp = RecvMessage(); if (tmp.Name() == ClientJoined.NameStatic) { clientJoinedMessage = (ClientJoined)tmp; break; } } if ((bool)clientJoinedMessage.Joined) { ai.SetSides(clientJoinedMessage.Sides, clientJoinedMessage.SideName); Logger.Log("Joined the game successfully"); Logger.Log("Side: " + clientJoinedMessage.SideName); return(true); } Logger.Log("Failed to join the game"); return(false); }
public void Loop() { while (true) { KSObject msg = RecvMessage(); if (msg is BaseSnapshot) { HandleSnapshot((BaseSnapshot)msg); } else if (msg.Name() == StartGame.NameStatic) { HandleStartGame(msg); } else if (msg.Name() == EndGame.NameStatic) { HandleEndGame((EndGame)msg); break; } } }
public void SendMessage(KSObject msg) { var data = parser.Encode(msg); network.SendData(data); }
private void SendMessage(KSObject msg) { protocol.SendMessage(msg); }
private void HandleStartGame(KSObject gamestart) { new Thread(() => SendCommandThread()).Start(); }