public void SendMessage(NetMessage message) { INetConnection connection = this as INetConnection; if (connection == null) { throw new InvalidOperationException("This connection did not impliment INetConnection and you cannot use this call."); } connection.SendMessage(message.FormatMessage(), message.EndPoint.Address.ToString(), message.EndPoint.Port); }
public void CreateNewPlayer(string ipaddr, int port) { IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(ipaddr), port); this.MakeInfoMessage(endpoint); NetMessage message = new NetMessage { EndPoint = endpoint, Text = "/ASKREPLY " + ipaddr + ":" + port.ToString(), MessageType = NetMessageTypes.GPGText }; this.QueueMessage(message); }
private void Game_OnNatMessage(SNatMessage NatMessage) { IPAddress address; NetMessage message = new NetMessage(); if (!IPAddress.TryParse(NatMessage.Address, out address)) { address = Dns.GetHostEntry(NatMessage.Address).AddressList[0]; } message.EndPoint = new IPEndPoint(address, NatMessage.Port); message.Buffer = NatMessage.Message; this.QueueMessage(message); }
private void mDriver_OnInput(object sender, Driver.InputEventArgs e) { string command = e.Command; foreach (object obj2 in e.Args) { if (obj2 != null) { command = command + " " + obj2.ToString(); } else { command = command + " (NULL)"; } } GPG.Logging.EventLog.WriteLine(command, LogCategory.Get("TCP"), new object[0]); if (e != null) { if (this.OnReceiveMessage != null) { if (e.Command == "ProcessNatPacket") { string address = (string) e.Args[0]; byte[] sourceArray = (byte[]) e.Args[1]; byte[] destinationArray = new byte[sourceArray.Length + 1]; Array.Copy(sourceArray, 0, destinationArray, 1, sourceArray.Length); destinationArray[0] = 8; NetMessage message = new NetMessage(destinationArray, NetworkUtils.ConvertAddress(address)); byte[] buffer3 = new byte[destinationArray.Length - 4]; Array.Copy(destinationArray, 4, buffer3, 0, destinationArray.Length - 4); message.Buffer = buffer3; this.OnReceiveMessage(message); } else { this.OnGetCommand(this, e); } } else { GPG.Logging.EventLog.WriteLine("There is nothing attached to OnReceiveMessage.", LogCategory.Get("TCP"), new object[] { e }); } } }
private void mConnection_OnReceiveMessage(NetMessage message) { EventLog.WriteLine("Traffic Manager received a message(" + message.MessageType.ToString() + "): " + message.EndPoint.Address.ToString() + " " + message.Text, LogCategory.Get("TrafficManager"), new object[0]); if (message.MessageType == NetMessageTypes.Nat) { Game.IncomingNatMessage("udp:/address=" + message.EndPoint.Address.ToString() + ";port=" + message.EndPoint.Port.ToString(), message.Buffer, message.Buffer.Length); EventLog.WriteLine("Registerd NAT traffic back to Quazal.", LogCategory.Get("TrafficManager"), new object[0]); if (message.Text.IndexOf("udp:/") < 0) { this.QueueMessage(this.MakeInfoMessage(message.EndPoint)); } } else if (message.MessageType == NetMessageTypes.GPGText) { string[] strArray = message.Text.Split(" ".ToCharArray(), 2); if (strArray.Length == 2) { string str2 = strArray[0]; string data = strArray[1]; switch (str2) { case "/PLAYERID": { PlayerInformation info = new PlayerInformation(data) { EndPoint = message.EndPoint }; if (info.PlayerName != User.Current.Name) { try { if (!this.mConnectAttempts.ContainsKey(info.PlayerName)) { this.mConnectAttempts.Add(info.PlayerName, 0); } int num = (int) this.mConnectAttempts[info.PlayerName]; num++; if (num < ConfigSettings.GetInt("PlayerIDResponseAttempts", 30)) { this.CreateNewPlayer(message.EndPoint.Address.ToString(), message.EndPoint.Port); this.mConnectAttempts[info.PlayerName] = num; } } catch (Exception exception) { ErrorLog.WriteLine(exception); } } if ((!this.mPlayerInfo.ContainsKey(info.PlayerID) || (this.mPlayerInfo[info.PlayerID] == null)) && (this.OnNewPlayer != null)) { this.OnNewPlayer(info); } this.mPlayerInfo[info.PlayerID] = info; goto Label_02E2; } case "/ASKREPLY": { string[] strArray2 = data.Split(new char[] { ':' }); IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(strArray2[0]), Convert.ToInt32(strArray2[1])); this.QueueMessage(this.MakeInfoMessage(endpoint)); this.QueueMessage(this.MakeInfoMessage(message.EndPoint)); goto Label_02E2; } } } } Label_02E2: if (this.OnReceiveMessage != null) { this.OnReceiveMessage(message); } }
public void QueueMessage(NetMessage message) { this.mMessageQueue.Enqueue(message); this.mMessageEvent.Set(); }
private void ProcessStdOut() { GPG.Logging.EventLog.WriteLine("StdOut Started", LogCategory.Get("SupcomStdInOut"), new object[0]); while (this.mProcessing) { int num = 0; try { GPG.Logging.EventLog.WriteLine("Waiting to do a readline", LogCategory.Get("SupcomStdInOut"), new object[0]); string str = this.mProcess.StandardOutput.ReadLine(); GPG.Logging.EventLog.WriteLine("Readline finished", LogCategory.Get("SupcomStdInOut"), new object[0]); if (str != null) { GPG.Logging.EventLog.WriteLine("STDOUT: " + str, LogCategory.Get("SupcomStdInOut"), new object[0]); num = 0; NetMessage message = new NetMessage { EndPoint = new IPEndPoint(IPAddress.Any, GamePort) }; message.Buffer = new byte[0]; if (str.IndexOf("/NAT ") == 0) { string data = str.Replace("/NAT ", ""); byte[] buffer2 = this.Decode(data); GPG.Logging.EventLog.WriteLine("Raw NAT Data: " + BitConverter.ToString(buffer2), LogCategory.Get("SupcomStdInOut"), new object[0]); if (buffer2.Length > 9) { byte[] destinationArray = new byte[buffer2.Length - 9]; Array.Copy(buffer2, 9, destinationArray, 0, destinationArray.Length); byte[] buffer4 = new byte[buffer2.Length - 5]; Array.Copy(buffer2, 5, buffer4, 0, buffer4.Length); buffer4[0] = 8; int port = (Convert.ToInt32(buffer2[5].ToString()) * 0x100) + Convert.ToInt32(buffer2[4].ToString()); string ipString = buffer2[3].ToString() + "." + buffer2[2].ToString() + "." + buffer2[1].ToString() + "." + buffer2[0].ToString(); GPG.Logging.EventLog.WriteLine("Raw Address: " + ipString, LogCategory.Get("SupcomStdInOut"), new object[0]); message.EndPoint = new IPEndPoint(IPAddress.Parse(ipString), port); GPG.Logging.EventLog.WriteLine("New Endpoint: " + message.EndPoint.ToString(), LogCategory.Get("SupcomStdInOut"), new object[0]); message.Buffer = destinationArray; if (buffer2[8] == 0) { message.MessageType = NetMessageTypes.Nat; } else if (buffer2[8] == 1) { message = new NetMessage(buffer4, message.EndPoint); } else if (buffer2[8] == 2) { message = new NetMessage(buffer4, message.EndPoint); } } } else { message.MessageType = NetMessageTypes.GameCommand; message.Text = str; } if (this.OnReceiveMessage != null) { this.OnReceiveMessage(message); } } else { GPG.Logging.EventLog.WriteLine("Setting Priority...", LogCategory.Get("SupcomStdInOut"), new object[0]); this.mStdOutThread.Priority = ThreadPriority.Normal; Thread.Sleep(100); num++; if (num > 100) { this.mProcessing = false; } } continue; } catch (ThreadInterruptedException exception) { GPG.Logging.EventLog.WriteLine("The thread was woken up: " + exception.Message, LogCategory.Get("SupcomStdInOut"), new object[0]); continue; } catch (Exception exception2) { ErrorLog.WriteLine(exception2.Message + "\r\n" + exception2.StackTrace, new object[0]); try { Thread.Sleep(100); } catch (ThreadInterruptedException exception3) { GPG.Logging.EventLog.WriteLine("The thread was woken up: " + exception3.Message, LogCategory.Get("SupcomStdInOut"), new object[0]); } continue; } } try { if (this.OnExit != null) { this.OnExit(this, EventArgs.Empty); } } catch (ThreadInterruptedException exception4) { GPG.Logging.EventLog.WriteLine("The thread was woken up: " + exception4.Message, LogCategory.Get("SupcomStdInOut"), new object[0]); } GPG.Logging.EventLog.WriteLine("StdOut Finished", LogCategory.Get("SupcomStdInOut"), new object[0]); }
public void ReceiveCallback(IAsyncResult ar) { if (this.mProcessing) { UdpClient client = (ar.AsyncState as UdpState).client; IPEndPoint endpoint = (ar.AsyncState as UdpState).endpoint; byte[] receiveBytes = client.EndReceive(ar, ref endpoint); if (this.OnReceiveMessage != null) { NetMessage message = new NetMessage(receiveBytes, endpoint); this.OnReceiveMessage(message); } this.SetUpReceive(); } }
public void ReceiveMessage(NetMessage message) { EventLog.WriteLine("Game Message: " + message.EndPoint.Address.ToString() + " " + message.Text, LogCategory.Get("SupComGameManager"), new object[0]); if (message.Text.IndexOf("/GAMEOPTION") == 0) { string[] strArray = message.Text.Split(" ".ToCharArray()); if (strArray.Length >= 4) { string playerName = strArray[2]; if (playerName.IndexOf("<") != 0) { for (int i = 3; i < (strArray.Length - 2); i++) { playerName = playerName + " " + strArray[i]; } string str2 = strArray[1]; string str3 = strArray[strArray.Length - 2]; string str4 = strArray[strArray.Length - 1]; this.mGameInfo.PlayerByName(playerName).Army = Convert.ToInt32(str3); switch (str2) { case "faction": { string str5 = "UEF"; switch (str4) { case "2": str5 = "Aeon"; break; case "3": str5 = "Cybran"; break; } this.mGameInfo.PlayerByName(playerName).Faction = str5; return; } case "color": this.mGameInfo.PlayerByName(playerName).Color = str4; return; case "team": { string str6 = "FFA"; switch (str4) { case "2": str6 = "Team 1"; break; case "3": str6 = "Team 2"; break; case "4": str6 = "Team 3"; break; case "5": str6 = "Team 4"; break; } this.mGameInfo.PlayerByName(playerName).Team = str6; return; } case "startspot": this.mGameInfo.PlayerByName(playerName).StartSpot = Convert.ToInt32(str4); return; } } } } else if (message.Text.IndexOf("/MAP") == 0) { string[] strArray2 = message.Text.Split(new char[] { '/' }); this.mGameInfo.Map = strArray2[strArray2.Length - 1].Replace(".scmap", ""); ThreadQueue.Quazal.Enqueue(typeof(Game), "UpdateGame", null, null, new object[] { this.mGameInfo.Map, 0, this.mGameInfo.GetMaxPlayers(), "", "", "" }); } else if (message.Text.IndexOf("/STATS") == 0) { if (message.Text != "/STATS End Stats") { if (message.Text == "/STATS Begin Stats") { this.mStats = ""; } else { string str9 = message.Text.Replace("/STATS ", "") + "\r\n"; while (str9.IndexOf("<LOC") >= 0) { int index = str9.IndexOf("<LOC"); str9 = str9.Remove(index, 4); if (str9.IndexOf(">") > 0) { str9 = str9.Remove(str9.IndexOf(">"), 1); } } this.mStats = this.mStats + str9; } } else { TimeSpan span = (TimeSpan) (DateTime.Now - this.mGameInfo.StartTime); string oldValue = "<GameStats xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"; string newValue = oldValue + "\r\n <GameInfo map=\"" + this.mGameInfo.Map + "\" starttime=\"" + this.mGameInfo.StartTime.ToUniversalTime().ToString() + "\" duration=\"" + span.TotalSeconds.ToString() + "\" gametype=\"Custom\">\r\n <PlayerInformation>\r\n"; foreach (SupcomPlayerInfo info in this.mGameInfo.Players) { newValue = newValue + " <Player name=\"" + info.PlayerName + "\" faction=\"" + info.Faction + "\" team=\"" + info.Team + "\" status=\"" + info.Status + "\" startposition=\"" + info.StartSpot.ToString() + "\" color=\"" + info.Color + "\"/>\r\n"; } newValue = newValue + " </PlayerInformation>\r\n" + " </GameInfo>\r\n"; this.mStats = this.mStats.Replace(oldValue, newValue); if (this.OnStatsXML != null) { this.OnStatsXML(this.mStats); } if (this.mStatsShutdown) { this.EndGame(); } } } else if (((message.Text.ToUpper() == "/GAMESTATE LOBBY") && (this.mGameState != GPG.Multiplayer.Game.GameState.Lobby)) && (this.mGameState != GPG.Multiplayer.Game.GameState.Launching)) { if (Chatroom.InChatroom) { Chatroom.JoinGame(); } this.mGameState = GPG.Multiplayer.Game.GameState.Lobby; this.mSupcomTCPConnection.SendMessage("LUA", new object[] { "LOG('This is a test.')" }); if (this.mIsHost) { ThreadQueue.Quazal.Enqueue(typeof(Game), "CreateGame", this, "FinishCreateGame", new object[] { this.mGameName, "Unknown Map", 0x5dc, 8, "SupCom", "1.0", this.GetParams() }); } else { ThreadQueue.Quazal.Enqueue(typeof(Game), "JoinGame", this, "FinishJoinGame", new object[] { this.mGameName }); } } else if ((message.Text.ToUpper() == "/GAMESTATE GAME IS RUNNING") && (this.mGameState != GPG.Multiplayer.Game.GameState.Playing)) { this.mGameState = GPG.Multiplayer.Game.GameState.Playing; this.MessageGame("//PLAYING " + User.Current.Name); this.mGameInfo.StartTime = DateTime.Now; } else if ((message.Text.ToUpper() == "/GAMESTATE LAUNCHING") && (this.mGameState != GPG.Multiplayer.Game.GameState.Launching)) { ThreadQueue.Quazal.Enqueue(typeof(Game), "StartGame", null, null, new object[0]); this.mGameState = GPG.Multiplayer.Game.GameState.Launching; this.MessageGame("//LAUNCHING " + User.Current.Name); } else if (message.Text.ToUpper().IndexOf("/GAMERESULT") == 0) { this.mStatsWatcher.Stop(); string[] strArray3 = message.Text.Split(" ".ToCharArray(), 3); if (strArray3.Length == 3) { this.mGameInfo.Sort(); this.mGameInfo.Players[Convert.ToInt32(strArray3[1]) - 1].Status = strArray3[2]; } int num3 = 0; foreach (SupcomPlayerInfo info2 in this.mGameInfo.Players) { if (info2.Status.ToUpper() == "DEFEAT") { num3++; } } if ((num3 + 1) == this.mGameInfo.Players.Count) { foreach (SupcomPlayerInfo info3 in this.mGameInfo.Players) { if (info3.Status.ToUpper() != "DEFEAT") { info3.Status = "victory"; } } } foreach (SupcomPlayerInfo info4 in this.mGameInfo.Players) { if (info4.PlayerName.ToUpper() == User.Current.Name.ToUpper()) { this.mStatsWatcher.Stop(); } } this.GetStats(); } else if (message.Text.ToUpper() == "/SENDSHUTDOWN") { this.EndGame(); } }