private void IncomingFunction() { try { InitializeClient(ref _incomingClient); GsService.AddServer(_localEP); while (_state == 0) { try { IPEndPoint remoteEP = null; byte[] buffer = _incomingClient.Receive(ref remoteEP); #if VERBOSE Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture) + " [UdpClient] " + Encoding.ASCII.GetString(buffer, 0, buffer.Length)); #endif if (Utils.EqualsTo(buffer, buffer.Length, _data[0])) { buffer = remoteEP.Address.GetAddressBytes(); Contract.Assert(buffer.Length == 4); long address = BitConverter.ToUInt32(buffer, 0); int port = remoteEP.Port; byte[] msg = _server.Status; Enqueue(address, port, msg); } else if (Utils.StartsWith(buffer, buffer.Length, _data[1])) { string id = Encoding.UTF8.GetString(buffer, _data[1].Length, buffer.Length - _data[1].Length); if (int.TryParse(id, NumberStyles.None, CultureInfo.InvariantCulture, out int clientId)) { _server.CheckClient(clientId); } } } catch (Exception) { } } } catch (Exception) { } finally { Close(); GsService.TryRemoveServer(_localEP); } }
private void UdpFunction() { IPEndPoint localEP = null; UdpClient client = null; try { localEP = new IPEndPoint(_localIP, CentralSwitchPort); client = new UdpClient(localEP); // adds the server profile and sets its default status message GsService.AddServer(localEP); byte[] serverStatus = Encoding.UTF8.GetBytes("\\gamename\\sfc2op\\gamever\\1.6\\location\\0\\serverver\\2.5.6.4\\validclientver\\2.5.6.4\\hostname\\Standard\\hostport\\" + CentralSwitchPort + "\\mapname\\StandardMap.mvm StandardMap.mvm StandardMap.mvm\\gametype\\Man-in-the-middle\\maxnumplayers\\3000\\numplayers\\0\\maxnumloggedonplayers\\64\\numloggedonplayers\\0\\gamemode\\Open\\racelist\\0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \\password\\\\final\\\\queryid\\1.1"); // starts receiving Dictionary <string, string> d = new Dictionary <string, string>(); while (true) { try { IPEndPoint dataEP = null; byte[] datagram = client.Receive(ref dataEP); Utils.GetArguments(datagram, datagram.Length, ref d); if (d.ContainsKey("status")) { client.Send(serverStatus, serverStatus.Length, dataEP); } d.Clear(); } catch (Exception) { } } } catch (Exception) { } finally { GsService.TryRemoveServer(localEP); client?.Close(); } }
public override int Process(AsyncUser user, byte[] buffer, int size) { // \valid\\email\[email protected]\final\ Dictionary <string, string> d = new Dictionary <string, string>(); Utils.GetArguments(buffer, size, ref d); if (d.ContainsKey("valid") && d.ContainsKey("email")) { if (GsService.ContainsEmail(d["email"])) { Write(user, _data[1], 0, _data[1].Length); } else { Write(user, _data[2], 0, _data[2].Length); } return(1); } return(0); }
public override int Process(AsyncUser user, byte[] buffer, int size) { Dictionary <string, string> d = new Dictionary <string, string>(); Utils.GetArguments(buffer, size, ref d); /* * \gamename\sfc2op\gamever\1.6\location\0\validate\Dvz0jxQz\final\ * \gamename\sfc2op\gamever\1.6\location\0\validate\Dvz0jxQz\final\\queryid\1.1\ * \gamename\sfc2op\gamever\1.6\location\0\validate\Dvz0jxQz\final\\queryid\1.1\\list\cmp\gamename\sfc2op\final\ */ if (d.ContainsKey("gamename")) { if (d.ContainsKey("list")) { using MemoryStream m = new MemoryStream(); GsService.ListServers(m); m.Write(_data[0], 0, _data[0].Length); // sends the list m.SetLength(m.Position); byte[] b = m.ToArray(); Write(user, b, 0, b.Length); } return(1); } return(0); }
static void Main(string[] args) { Contract.Requires(args != null); //KillProcess("StarFleetOP"); // gets the current list of IPs string hostName = Dns.GetHostName(); IPHostEntry hostEntry = Dns.GetHostEntry(hostName); IPAddress[] hostAddressList = hostEntry.AddressList; List <string> AddressList = new List <string>(); Console.WriteLine("Address list:"); Console.WriteLine(); string data; for (int i = 0; i < hostAddressList.Length; i++) { if (hostAddressList[i].AddressFamily == AddressFamily.InterNetwork) { data = hostAddressList[i].ToString(); Console.WriteLine(AddressList.Count.ToString(CultureInfo.InvariantCulture) + ". " + data); AddressList.Add(data); } } Console.WriteLine(); Console.Write("Local address: "); data = Console.ReadLine(); if (!int.TryParse(data, NumberStyles.Integer, CultureInfo.InvariantCulture, out int AddressIndex) || AddressIndex < 0 || AddressIndex >= AddressList.Count) { return; } Console.WriteLine(); data = AddressList[AddressIndex]; IPAddress privateIP = IPAddress.Parse(data); IPAddress publicIP = IPAddress.Parse(data); Contract.Requires(privateIP != null && publicIP != null); // starts the services #if DEBUG string appDirectory = "C:/Users/D4v1k/Documents/My Games/Starfleet Command 2 Orion Pirates"; #else string appDirectory = AppContext.BaseDirectory; #endif if (!Directory.Exists(appDirectory)) { Console.WriteLine("ERROR: directory not found!"); return; } AssemblyName app = Assembly.GetEntryAssembly().GetName(); string appName = app.Name + " " + app.Version.ToString(); string[] motd = { "<!DOCTYPE html><html><head><title>Index</title></head><body>Under construction...</body></html>", appName + " 1.0 (C) D4v1ks", "SFC2EAW 2.0.3.7 Patch (C) TarMinyatur, D4v1ks, Adam", "SFC2OP 2.5.6.4 Patch (C) D4v1ks, TarMinyatur, Adam, Javora, Darkdrone, Falconer", "SFC3 HD/Gamespy Patch (C) D4v1ks, Falconer" }; // ... Directory Server80.Initialize(appName, motd); Server15101.Initialize(publicIP); Server15300.Initialize(); using Server80 server80 = new Server80(); using Server15101 server15101 = new Server15101(); using Server15300 server15300 = new Server15300(); server80.Start(privateIP); server15101.Start(privateIP); server15300.Start(privateIP); // ... Gamespy GsService.Initialize(); Server28900.Initialize(); Server29900.Initialize(); Server29901.Initialize(); using Server28900 server28900 = new Server28900(); using Server29900 server29900 = new Server29900(); using Server29901 server29901 = new Server29901(); server28900.Start(privateIP); server29900.Start(privateIP); server29901.Start(privateIP); // ... InternetRelayChat IrcService.InitializeAndStart(motd, privateIP); // selects a server #if DEBUG Console.Write("You want to (r)un the new server or (d)ebug a stock server? "); data = Console.ReadLine(); #else Console.Write("Starting the new server..."); data = "r"; #endif Console.WriteLine(); // tries to launch the server GameServer server = null; if (data.Equals("r", StringComparison.Ordinal)) { GameServer.Initialize(); server = new GameServer(privateIP, 27000, appDirectory, "2.5.6.4"); server.Start(); } #if DEBUG else if (data.Equals("d", StringComparison.Ordinal)) { // makes sure no stock server is running in the background KillProcess("ServerPlatform"); // makes sure the stock server is configured with the settings we need GameFile gf = new GameFile(); // ... ServerSetup.gf gf.Load(appDirectory + "/Assets/Settings/Dedicated/Standard/ServerSetup.gf"); if (gf.TryGetValue("CentralSwitchSetup", "CentralSwitchPort", out int port) && port != 27001) { gf.AddOrUpdate("CentralSwitchSetup", "CentralSwitchPort", 27001); gf.Save(); } gf.Clear(); // ... Chat.gf gf.Load(appDirectory + "/Assets/Settings/Dedicated/Chat.gf"); if (gf.TryGetValue("Server", "NickName", out string nick, out bool quotes) && !nick.Equals("A1", StringComparison.Ordinal)) { gf.AddOrUpdate("Server", "NickName", "A1", true); gf.AddOrUpdate("Server", "Name", "A1", true); gf.AddOrUpdate("Server", "VerboseName", "A1", true); gf.Save(); } gf.Clear(); Thread.Sleep(500); // launches the stock server as a separated process ProcessStartInfo startInfo = new ProcessStartInfo() { WorkingDirectory = appDirectory, FileName = appDirectory + "/ServerPlatform.exe", UseShellExecute = true }; Process.Start(startInfo); // VERY IMPORTANT: it is assumed here that the stock server has at least run once, previously, using the SFC Launcher ManInTheMiddle mitm = new ManInTheMiddle(privateIP); } #endif else { Console.WriteLine("Invalid option!"); } // waits for input Console.WriteLine("Press ENTER, at any time, to exit..."); Console.ReadLine(); // closes everything server?.Close(); }
public override int Process(AsyncUser user, byte[] buffer, int size) { Contract.Requires(user != null); Dictionary <string, string> d = new Dictionary <string, string>(); Utils.GetArguments(buffer, size, ref d); // \newuser\\email\[email protected]\nick\JohnDoe2\password\sfcrulz\id\1\final\ if (d.ContainsKey("newuser") && d.ContainsKey("email") && d.ContainsKey("nick") && d.ContainsKey("password")) { if (GsService.ContainsEmail(d["email"])) { Write(user, _data[2], 0, _data[2].Length); } else if (GsService.ContainsNick(d["nick"])) { Write(user, _data[3], 0, _data[3].Length); } else { GsService.AddProfile(d["email"], d["nick"], d["password"], out GsProfile profile); // \nur\\userid\12617\profileid\19465\id\1\final\ StringBuilder s = new StringBuilder(1024); s.Append("\\nur\\\\userid\\"); s.Append(profile.Id); s.Append("\\profileid\\"); s.Append(profile.Id); s.Append("\\id\\1\\final\\"); byte[] b = Encoding.ASCII.GetBytes(s.ToString()); Write(user, b, 0, b.Length); } return(1); } /* * \login\\challenge\IoWIbSnjMf2pv9iUioRgF9ySYLV2r72p\user\JohnDoe2@[email protected]\userid\12617\profileid\19465\response\08eeb76f1241ac0777a18aac726c03d1\firewall\1\port\0\id\1\final\ * \login\\challenge\PKPNiLeCH1D71pCwSndbT36zrkQLaG2w\user\JohnDoe2@[email protected]\response\a7d6e62a66f96565966f96ab475a44cf\firewall\1\port\0\id\1\final\ */ if (d.ContainsKey("login") && d.ContainsKey("challenge") && d.ContainsKey("user") && d.ContainsKey("response")) { GsService.GetProfile(d["user"], out GsProfile profile); if (profile != null) { using MD5 md5 = MD5.Create(); string password = GetHash(md5, profile.Password); string userData = password + " " + profile.Username; string clientChallenge = d["challenge"]; string clientResponse = GetHash(md5, userData + clientChallenge + _serverChallenge + password); string serviceResponse = GetHash(md5, userData + _serverChallenge + clientChallenge + password); if (clientResponse.Equals(d["response"], StringComparison.Ordinal)) { // \lc\2\sesskey\239289\proof\8f1295968d534a3c6816d24dc172d92e\userid\12617\profileid\19465\uniquenick\JohnDoe2@[email protected]\lt\x4TGX3[SbkAk]NIJt3Hc4N__\id\1\final\ StringBuilder s = new StringBuilder(1024); s.Append("\\lc\\2\\sesskey\\"); s.Append(user.Id); s.Append("\\proof\\"); s.Append(serviceResponse); s.Append("\\userid\\"); s.Append(profile.Id); s.Append("\\profileid\\"); s.Append(profile.Id); s.Append("\\uniquenick\\"); s.Append(profile.Username); s.Append("\\lt\\x4TGX3[SbkAk]NIJt3Hc4N__\\id\\1\\final\\"); byte[] b = Encoding.ASCII.GetBytes(s.ToString()); Write(user, b, 0, b.Length); if (d.ContainsKey("userid") && d.ContainsKey("profileid")) { return(1); } else { return(0); } } } Write(user, _data[4], 0, _data[4].Length); return(1); } // \logout\\sesskey\239288\final\ if (d.ContainsKey("logout")) { return(1); } return(0); }