private Task WaitForClient() { socket.Close(); return(Task.Factory.StartNew(() => { byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 28960); newsock = new UdpClient(ipep); Print.Info("Waiting for a client..."); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); while (!iSClosing) { try { data = newsock.Receive(ref sender); string message = Encoding.ASCII.GetString(data, 0, data.Length); PacketReceived(this, new PacketReceivedEventArgs { from = sender, message = Encoding.ASCII.GetString(data, 0, data.Length).Substring(4), type = message.Contains("getstatus") ? PacketReceivedType.GETSTATUS : PacketReceivedType.GETINFO, stream = newsock }); } catch (Exception e) { Print.Error(e.Message); } } })); }
public FserverManager(string jsonpath) { if (File.Exists(jsonpath)) { Print.Success(jsonpath + " Found"); } else { Print.Error(jsonpath + "Not found", true); } this.jsonpath = jsonpath; }
private void Init() { try { Print.Info(Tag + ": Initialzing Socket"); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Bind(new IPEndPoint(IPAddress.Any, Port)); Print.Success(Tag + ": Socket Bound to Port " + Port); ConnectToMasterServer(); Send(PacketTypes.HeartBeat_Flat); Thread.Sleep(1000); Send(PacketTypes.HeartBeat); } catch (Exception e) { Print.Error(e.Message); } }
private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { try { iSClosing = true; newsock.Close(); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Bind(new IPEndPoint(IPAddress.Any, Port)); socket.Connect(masterserver); Send(PacketTypes.HeartBeat_Flat); Print.Success("Closing Server with flatline"); Print.Info("\nPress any key to exit"); Console.ReadKey(); Environment.Exit(0); } catch (Exception x) { Print.Error(x.Message); Environment.Exit(0); } }
public void Init() { Print.Info("Parsing " + this.jsonpath + ".."); try { FServers = JsonConvert.DeserializeObject <List <FServer> >(File.ReadAllText(this.jsonpath)); string servers = "["; foreach (FServer s in FServers) { servers += "^2" + s.Tag + "^7:^2" + s.Port + "^7,"; } Print.Success(this.jsonpath + " loaded with ^2" + FServers.Count + " ^7entries " + servers.Substring(0, servers.Length - 1) + "]"); } catch (Exception e) { Print.Error(e.Message); } }