public bool Start(NewPlayerInfo playerInfo, int port) { listener = new EventBasedNetListener(); server = new NetManager(listener); localPacketProcessor = new NetPacketProcessor(); Console.WriteLine("started instances..."); localPacketProcessor.SubscribeReusable <ZeroGPacket, NetPeer>(OnDataRecieve); if (!server.Start(port)) { Console.WriteLine("Failed to start server"); //return false; throw new Exception("Failed to start server..."); } newPlayerData = playerInfo; listener.ConnectionRequestEvent += Listener_ConnectionRequestEvent; listener.NetworkReceiveEvent += Listener_NetworkReceiveEvent; listener.PeerConnectedEvent += Listener_PeerConnectedEvent; listener.PeerDisconnectedEvent += Listener_PeerDisconnectedEvent; zeroPacketProcessor = new ProcessPacket(); InstanceKeeper.SetServerinstance(this); GetEvents(); // while (/*!Console.KeyAvailable*/1-1==0) //{ // server.PollEvents(); // Thread.Sleep(15); // } // this.server.Stop(); return(true); }
public void Start(string serverip, int port, string username) { try { playername = username; packetProcessor = new ProcessPacket(); listener = new EventBasedNetListener(); client = new NetManager(listener); netPackProc = new NetPacketProcessor(); netPackProc.SubscribeReusable <ZeroGPacket, NetPeer>(ProcessPacket); listener.NetworkReceiveEvent += Listener_NetworkReceiveEvent; listener.PeerConnectedEvent += Listener_PeerConnectedEvent; listener.PeerDisconnectedEvent += Listener_PeerDisconnectedEvent; WriteLog.General("Created NetworkRecieveEvent and PeerConnectedEvent"); WriteLog.General("Created eventbased listener and client"); WriteLog.Debug("Attempting to connect to game server"); client.UpdateTime = 10; client.UnsyncedEvents = true; client.Start(); if (File.Exists("config.ini")) { string text = File.ReadAllText("config.ini"); string[] parts = text.Split(':'); client.Connect(parts[0], int.Parse(parts[1]), "ZeroG"); WriteLog.Debug("Game client attempting to connect to " + parts[0] + ":" + parts[1]); } else { //client.Connect("127.0.0.1", 6001, "ZeroG"); WriteLog.Debug("Game client attempting to connect to " + serverip + ":" + port.ToString()); client.Connect(serverip, port, "ZeroG"); } resetEvent.WaitOne(2000); resetEvent.Reset(); } catch (Exception ex) { WriteLog.Error("Error while trying to connect: " + ex.Message + ex.StackTrace); } }
public static void maid() { packet = new ProcessPacket(); }