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 }); } } }
public SupcomTCPConnection(bool automatch, string path, string arguements, string address, int port, bool isReplay, bool isHost) { AsyncCallback callback = null; this.mMutex = new object(); this.mSupcomPort = -1; this.mConnectionID = -1; string str = path; if (ConfigSettings.GetBool("UseHidden", false)) { str = str.Replace("SupremeCommander.exe", "GalLoader.exe"); if (!System.IO.File.Exists(str)) { str = path; } } if (!isReplay) { this.mListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); this.mListener.Bind(new IPEndPoint(IPAddress.Loopback, 0)); this.mListener.Listen(1); IPEndPoint localEndPoint = (IPEndPoint) this.mListener.LocalEndPoint; string arguments = ""; if ((GPGnetSelectedGame.SelectedGame != null) && (GPGnetSelectedGame.SelectedGame.ForcedCommandLineArgs != "")) { arguments = GPGnetSelectedGame.SelectedGame.ForcedCommandLineArgs.Replace("%STANDARDARGS", arguements).Replace("%PLAYERNAME", User.Current.Name).Replace("%GPGNET", localEndPoint.ToString()); } else { arguments = string.Format("{0} /profile {1} /gpgnet {2}", arguements, User.Current.Name, localEndPoint); } if ((GPGnetSelectedGame.SelectedGame != null) && (GPGnetSelectedGame.SelectedGame.UserForcedCommandLineArgs != "")) { arguments = arguments + " " + GPGnetSelectedGame.SelectedGame.UserForcedCommandLineArgs; } if ((GPGnetSelectedGame.SelectedGame != null) && (GPGnetSelectedGame.SelectedGame.GameID == 2)) { arguments = arguments.Replace("/seraphim", "/uef"); } ProcessStartInfo startInfo = new ProcessStartInfo(str, arguments); GPG.Logging.EventLog.WriteLine("Application Name: " + path, LogCategory.Get("TCP"), new object[0]); GPG.Logging.EventLog.WriteLine("Application arguements: " + arguments, LogCategory.Get("TCP"), new object[0]); startInfo.UseShellExecute = true; string str3 = path.Substring(0, path.LastIndexOf(@"\")); GPG.Logging.EventLog.WriteLine("Working Directory: " + str3, LogCategory.Get("TCP"), new object[0]); startInfo.WorkingDirectory = str3; this.mProcess = Process.Start(startInfo); this.mIsRunningThread = new Thread(new ThreadStart(this.CheckIsRunning)); this.mIsRunningThread.IsBackground = true; this.mIsRunningThread.Start(); if (callback == null) { callback = delegate (IAsyncResult result) { Socket socket = this.mListener.EndAccept(result); lock (this.mMutex) { this.mSocket = socket; this.mDriver = new Driver(this.mSocket); this.mDriver.OnInput += new EventHandler<Driver.InputEventArgs>(this.mDriver_OnInput); this.mDriver.Start(); this.SendMessage("Test", new object[0]); int num = automatch ? 1 : 0; if (GPGnetSelectedGame.ProfileName == "") { GPGnetSelectedGame.ProfileName = User.Current.Name; } if (isHost && GPGnetSelectedGame.IsSpaceSiege) { if (ConfigSettings.GetBool("GetSpaceSiegeHostOldWay", false)) { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, 1 }); } else { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, User.Current.ID, GPGnetSelectedGame.ProfileName }); } } else if (GPGnetSelectedGame.IsSpaceSiege) { if (ConfigSettings.GetBool("GetSpaceSiegeHostOldWay", false)) { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, User.Current.ID }); } else { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, User.Current.ID, GPGnetSelectedGame.ProfileName }); } } else { bool hasOriginal = false; bool hasExpansion = false; GPGnetSelectedGame.TestFactions(out hasOriginal, out hasExpansion); if ((GPGnetSelectedGame.SelectedGame.GameDescription == "Forged Alliance") || (GPGnetSelectedGame.SelectedGame.GameDescription == "Forged Alliance Beta")) { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, User.Current.ID, Convert.ToInt32(hasOriginal) }); } else { this.SendMessage("CreateLobby", new object[] { num, SupcomStdInOut.GamePort, User.Current.Name, User.Current.ID }); } } this.CheckSpaceSiegeMessages(); } }; } this.mListener.BeginAccept(callback, null); } else { string str4 = string.Format("{0} /profile {1}", arguements, User.Current.Name); ProcessStartInfo info2 = new ProcessStartInfo(str, str4); GPG.Logging.EventLog.WriteLine("REPLAY Application Name: " + path, LogCategory.Get("TCP"), new object[0]); GPG.Logging.EventLog.WriteLine("REPLAY Application arguements: " + str4, LogCategory.Get("TCP"), new object[0]); info2.UseShellExecute = true; string str5 = path.Substring(0, path.LastIndexOf(@"\")); GPG.Logging.EventLog.WriteLine("REPLAY Working Directory: " + str5, LogCategory.Get("TCP"), new object[0]); info2.WorkingDirectory = str5; this.mProcess = Process.Start(info2); this.mIsRunningThread = new Thread(new ThreadStart(this.CheckIsRunning)); this.mIsRunningThread.IsBackground = true; this.mIsRunningThread.Start(); } }
private void mSupcomTCPConnection_OnGetCommand(object sender, Driver.InputEventArgs e) { EventLog.WriteLine("Got a command from the game: ", LogCategory.Get("SupComGameManager"), new object[] { e }); if (!(e.Command == "GameOption")) { if (e.Command == "Terminate") { string message = ""; foreach (string str3 in e.Args) { message = message + str3 + " "; } if (message == "") { message = "The game has been closed with the Terminate arguement. Please provide a reason after the Terminate command to provide context."; } this.ForceCloseGame(message); } else if (e.Command == "PlayerOption") { string[] strArray2 = ("/PLAYEROPTION " + ((string) e.Args[0])).Split(" ".ToCharArray()); if (strArray2.Length >= 4) { string playerName = strArray2[2]; if (playerName.IndexOf("<") != 0) { for (int i = 3; i < (strArray2.Length - 2); i++) { playerName = playerName + " " + strArray2[i]; } string str5 = strArray2[1]; string str6 = strArray2[strArray2.Length - 2]; string str7 = strArray2[strArray2.Length - 1]; this.mGameInfo.PlayerByName(playerName).Army = Convert.ToInt32(str6); switch (str5) { case "faction": { string str8 = "UEF"; switch (str7) { case "2": str8 = "Aeon"; break; case "3": str8 = "Cybran"; break; case "4": str8 = "Seraphim"; break; } this.mGameInfo.PlayerByName(playerName).Faction = str8; return; } case "color": this.mGameInfo.PlayerByName(playerName).Color = str7; return; case "team": { string str9 = "FFA"; switch (str7) { case "2": str9 = "Team 1"; break; case "3": str9 = "Team 2"; break; case "4": str9 = "Team 3"; break; case "5": str9 = "Team 4"; break; } this.mGameInfo.PlayerByName(playerName).Team = str9; return; } case "startspot": this.mGameInfo.PlayerByName(playerName).StartSpot = Convert.ToInt32(str7); return; } } } } else if (e.Command == "Stats") { string str10 = (string) e.Args[0]; str10 = str10.Replace("<LOC", "<LOC").Replace("_desc>", "_desc>"); this.mStats = str10; foreach (SupcomPlayerInfo info in this.mGameInfo.Players) { info.UnitInfo.Clear(); } try { string str11 = ""; foreach (string str12 in str10.Split(new char[] { '\n' })) { if (str12.ToUpper().IndexOf("<ARMY") >= 0) { string[] strArray4 = str12.Split(new char[] { '"' }); if (strArray4.Length >= 3) { int num2 = Convert.ToInt32(strArray4[1]); string str13 = strArray4[3]; str11 = str13; foreach (SupcomPlayerInfo info2 in this.mGameInfo.Players) { if (info2.PlayerName == str13) { info2.Army = num2; break; } } } } else if ((str12.ToUpper().IndexOf("<ENERGY PRODUCED=\"") >= 0) && (str11 != "")) { double num3 = 0.0; double num4 = 0.0; foreach (string str14 in str12.Split(new char[] { ' ' })) { try { string[] strArray5 = str14.Split("=".ToCharArray(), 2); if (strArray5.Length == 2) { try { if (strArray5[0].ToLower() == "produced") { num4 += Convert.ToDouble(strArray5[1].Replace("\"", "")); } else if (strArray5[0].ToLower() == "consumed") { num3 += Convert.ToDouble(strArray5[1].Replace("\"", "")); } } catch (Exception exception) { ErrorLog.WriteLine(exception); } } } catch (Exception exception2) { ErrorLog.WriteLine(exception2); } } foreach (SupcomPlayerInfo info3 in this.mGameInfo.Players) { if (info3.PlayerName == str11) { info3.EnergyConsumed = num3; info3.EnergyProduced = num4; break; } } } else if ((str12.ToUpper().IndexOf("<MASS PRODUCED=\"") >= 0) && (str11 != "")) { double num5 = 0.0; double num6 = 0.0; foreach (string str15 in str12.Split(new char[] { ' ' })) { try { string[] strArray6 = str15.Split("=".ToCharArray(), 2); if (strArray6.Length == 2) { try { if (strArray6[0].ToLower() == "produced") { num6 += Convert.ToDouble(strArray6[1].Replace("\"", "")); } else if (strArray6[0].ToLower() == "consumed") { num5 += Convert.ToDouble(strArray6[1].Replace("\"", "")); } } catch (Exception exception3) { ErrorLog.WriteLine(exception3); } } } catch (Exception exception4) { ErrorLog.WriteLine(exception4); } } foreach (SupcomPlayerInfo info4 in this.mGameInfo.Players) { if (info4.PlayerName == str11) { info4.MassConsumed = num5; info4.MassProduced = num6; break; } } } else if ((str12.ToUpper().IndexOf("<UNIT ID=\"") >= 0) && (str11 != "")) { string str16 = ""; int num7 = 0; int num8 = 0; int num9 = 0; double num10 = 0.0; double num11 = 0.0; foreach (string str17 in str12.Split(new char[] { ' ' })) { try { string[] strArray7 = str17.Split("=".ToCharArray(), 2); if (strArray7.Length == 2) { try { if (strArray7[0].ToLower() == "id") { str16 = strArray7[1].Replace("\"", ""); } else if (strArray7[0].ToLower() == "built") { num7 += Convert.ToInt32(strArray7[1].Replace("\"", "")); } else if (strArray7[0].ToLower() == "lost") { num8 += Convert.ToInt32(strArray7[1].Replace("\"", "")); } else if (strArray7[0].ToLower() == "killed") { num9 += Convert.ToInt32(strArray7[1].Replace("\"", "")); } else if (strArray7[0].ToLower() == "damagedealt") { num10 += Convert.ToDouble(strArray7[1].Replace("\"", "")); } else if (strArray7[0].ToLower() == "damagereceived") { num11 += Convert.ToDouble(strArray7[1].Replace("\"", "")); } } catch (Exception exception5) { ErrorLog.WriteLine(exception5); } } } catch (Exception exception6) { ErrorLog.WriteLine(exception6); } } num7 += num8; foreach (SupcomPlayerInfo info5 in this.mGameInfo.Players) { if (info5.PlayerName == str11) { SupcomUnitInfo item = new SupcomUnitInfo { unitid = str16, built = num7, lost = num8, killed = num9, damagedealt = num10, damagereceived = num11 }; info5.UnitInfo.Add(item); } } if ((str12.ToUpper().IndexOf("<UNIT ID=\"UEL0001\"") >= 0) && (str11 != "")) { if ((str12.ToUpper().IndexOf("BUILT=\"1\"") > 0) || (str12.ToUpper().IndexOf("LOST=\"1\"") > 0)) { foreach (SupcomPlayerInfo info7 in this.mGameInfo.Players) { if (info7.PlayerName == str11) { info7.Faction = "UEF"; break; } } } } else if ((str12.ToUpper().IndexOf("<UNIT ID=\"UAL0001\"") >= 0) && (str11 != "")) { if ((str12.ToUpper().IndexOf("BUILT=\"1\"") > 0) || (str12.ToUpper().IndexOf("LOST=\"1\"") > 0)) { foreach (SupcomPlayerInfo info8 in this.mGameInfo.Players) { if (info8.PlayerName == str11) { info8.Faction = "Aeon"; break; } } } } else if ((str12.ToUpper().IndexOf("<UNIT ID=\"URL0001\"") >= 0) && (str11 != "")) { if ((str12.ToUpper().IndexOf("BUILT=\"1\"") > 0) || (str12.ToUpper().IndexOf("LOST=\"1\"") > 0)) { foreach (SupcomPlayerInfo info9 in this.mGameInfo.Players) { if (info9.PlayerName == str11) { info9.Faction = "Cybran"; break; } } } } else if (((str12.ToUpper().IndexOf("<UNIT ID=\"XSL0001\"") >= 0) && (str11 != "")) && ((str12.ToUpper().IndexOf("BUILT=\"1\"") > 0) || (str12.ToUpper().IndexOf("LOST=\"1\"") > 0))) { foreach (SupcomPlayerInfo info10 in this.mGameInfo.Players) { if (info10.PlayerName == str11) { info10.Faction = "Seraphim"; break; } } } } } this.ProcessGameResults(); } catch (Exception exception7) { ErrorLog.WriteLine(exception7); } if (!this.IsRegularRankedGame()) { 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"; if (this.mGameInfo != null) { foreach (SupcomPlayerInfo info11 in this.mGameInfo.Players) { newValue = newValue + " <Player name=\"" + info11.PlayerName + "\" faction=\"" + info11.Faction + "\" team=\"" + info11.Team + "\" status=\"" + info11.Status + "\" startposition=\"" + info11.StartSpot.ToString() + "\" color=\"" + info11.Color + "\"/>\r\n"; } } newValue = newValue + " </PlayerInformation>\r\n" + " </GameInfo>\r\n"; this.mStats = this.mStats.Replace(oldValue, newValue); } else { foreach (SupcomPlayerInfo info12 in this.mGameInfo.Players) { foreach (string str20 in this.mStats.Split("\r\n".ToCharArray())) { if ((str20.IndexOf("\"" + info12.PlayerName + "\"") >= 0) && (str20.IndexOf("victory") >= 0)) { info12.Status = "victory"; } if ((str20.IndexOf("\"" + info12.PlayerName + "\"") >= 0) && (str20.IndexOf("defeat") >= 0)) { info12.Status = "defeat"; } if (str20.IndexOf("GameInfo") >= 0) { foreach (string str21 in str20.Split(new char[] { ' ' })) { if (str21.IndexOf("starttime") >= 0) { try { this.mGameInfo.StartTime = DateTime.Parse(str21.Replace("starttime", "").Replace("\"", "").Trim()); } catch { } } } } } } } if (this.OnStatsXML != null) { this.OnStatsXML(this.mStats); } } else if (e.Command == "Desync") { this.ForceCloseGame(Loc.Get("<LOC>The game has desynced and has been shut down.")); } else { if (e.Command == "Bottleneck") { if (ConfigSettings.GetBool("AutoDisconnect", true)) { try { if (Convert.ToDouble(e.Args[3]) > ConfigSettings.GetInt("AutoTime", 0x7530)) { this.MessageGame("//DISCPLAYER " + e.Args[2].ToString()); } } catch (Exception exception8) { ErrorLog.WriteLine(exception8); } } if (!ConfigSettings.GetBool("LogBottlenecks", true)) { return; } try { string str22 = ""; foreach (object obj2 in e.Args) { str22 = str22 + obj2.ToString() + " "; } double num13 = Convert.ToDouble(e.Args[3]); if ((Environment.TickCount - this.mBottleNeckCooldown) > ConfigSettings.GetInt("BottleNeckCooldown", 0x7530)) { if (num13 > ConfigSettings.GetInt("AutoTime", 0x7530)) { ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "GameEvent", new object[] { User.Current.ID, "Bottleneck", str22, this.GameName, this.GameName } }); } this.mBottleNeckCooldown = Environment.TickCount; } return; } catch (Exception exception9) { ErrorLog.WriteLine(exception9); return; } } if (e.Command == "GameState") { string str23 = (string) e.Args[0]; if (str23 != "Idle") { if (((str23 == "Lobby") && (this.mGameState != GPG.Multiplayer.Game.GameState.Lobby)) && (this.mGameState != GPG.Multiplayer.Game.GameState.Launching)) { if (this.MyTeam != "") { this.MessageGame("//TEAMNAME " + this.MyTeam); } if (Chatroom.InChatroom) { Chatroom.JoinGame(); } this.mGameState = GPG.Multiplayer.Game.GameState.Lobby; if (this.mIsHost) { ThreadQueue.Quazal.Enqueue(typeof(Game), "CreateGame", this, "FinishCreateGame", new object[] { this.mGameName, "Unknown Map", 0x5dc, 8, "SupCom", "1.0", this.GetParams() }); ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "GameEvent", new object[] { User.Current.ID, "HostedGame", this.mGameName, this.mGameName, this.mGameName } }); } else { ThreadQueue.Quazal.Enqueue(typeof(Game), "JoinGame", this, "FinishJoinGame", new object[] { this.mGameName }); } } else if ((str23 == "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 ((str23 == "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; if (this.OnGameLaunched != null) { this.OnGameLaunched(this, EventArgs.Empty); } this.MessageGame("//PLAYERINFO " + User.Current.ID.ToString() + " " + User.Current.Name + " -1"); if (this.mIsHost) { ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "GameEvent", new object[] { User.Current.ID, "LaunchedGame: " + this.mGameInfo.Map, this.mGameName, this.mGameName, this.mGameName } }); ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "GameEvent", new object[] { User.Current.ID, "Map", this.mGameInfo.Map, this.mGameName, this.mGameName } }); this.MessageGame("//MAP " + this.mGameInfo.Map); if (this.MyTeam != "") { this.MessageGame("//TEAMNAME " + this.MyTeam); } foreach (SupcomPlayerInfo info13 in this.mGameInfo.Players) { this.MessageGame("//PLAYERINFO " + info13.PlayerID.ToString() + " " + info13.PlayerName + " " + info13.Army.ToString()); } } else if (ConfigSettings.GetBool("LogJoins", true)) { ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "GameEvent", new object[] { User.Current.ID, "JoinedLaunchedGame: " + this.mGameInfo.Map, this.mGameName, this.mGameName, this.mGameName } }); } this.MessageGame("//LAUNCHING " + User.Current.Name); if (this.DoReplay) { ThreadQueue.Quazal.Enqueue(typeof(DataAccess), "ExecuteQuery", null, null, new object[] { "ReplayLaunched", new object[] { this.mReplayID } }); } } } } else if (e.Command == "GameResult") { this.mResultsQueue.Add(e); } } } else if (((string) e.Args[0]) == "ScenarioFile") { string[] strArray = ((string) e.Args[1]).Split(new char[] { '/' }); this.mGameInfo.Map = (string) e.Args[1]; foreach (string str in strArray) { if (str.ToUpper().IndexOf("SCMP") == 0) { this.mGameInfo.Map = str.ToUpper(); break; } } ThreadQueue.Quazal.Enqueue(typeof(Game), "UpdateGame", null, null, new object[] { this.mGameInfo.Map, 0, this.mGameInfo.GetMaxPlayers(), "", "", "" }); } }