public void StartParent() { if (IsParentRunning) { SetOnException("Cannot start Parent Server because it is already running."); } else { ParentServer.OnClientConnect += ParentServer_OnClientConnect; ParentServer.OnClientSend += ParentServer_OnClientSend; ParentServer.OnClientReceive += ParentServer_OnClientReceive; ParentServer.OnClientDisconnect += ParentServer_OnClientDisconnect; ParentServer.OnClientException += ParentServer_OnClientException; ParentServer.OnClientBlackList += ParentServer_OnClientBlackList; ParentServer.PacketManager = CreateCommands(); StartListenerResult ListenerResult = ParentServer.StartListener(); if (ListenerResult.IsOperationSuccess) { StartAcceptorResult AcceptorResult = ParentServer.StartAcceptor(); if (AcceptorResult.IsOperationSuccess) { IsParentRunning = true; SetOnParentCreated(string.Format("{0}\n{1}", ListenerResult.Message, AcceptorResult.Message)); for (int i = 0; i < ParentConfig.MaximumChildrenInstances; i++) { CreateChild(); } } else { SetOnException(AcceptorResult.Message); } } else { SetOnException(ListenerResult.Message); } } }
public void Start() { StartListenerResult ListenerResult = ServerInstance.StartListener(); if (ListenerResult.IsOperationSuccess) { Logger.Log(new Log(ListenerResult.Message, ConsoleColor.Green)); StartAcceptorResult AcceptorResult = ServerInstance.StartAcceptor(); if (AcceptorResult.IsOperationSuccess) { Logger.Log(new Log(AcceptorResult.Message, ConsoleColor.Green)); AddServerHandlers(); } else { Logger.Log(new Log(AcceptorResult.Message, ConsoleColor.Red)); } } else { Logger.Log(new Log(ListenerResult.Message, ConsoleColor.Red)); } }
/// <summary> /// Starts Establishing Incoming Connections /// </summary> /// <returns></returns> public StartAcceptorResult StartAcceptor() { StartAcceptorResult AcceptorResult; try { if (!IsListening) { AcceptorResult = new StartAcceptorResult("Client Acceptor could not start since the server did not start listening", "StartAcceptor", DateTime.Now, false); } else { StartAccept(null); AcceptorResult = new StartAcceptorResult("Client Acceptor started successfully", "StartAcceptor", DateTime.Now, true); } return(AcceptorResult); } catch { AcceptorResult = new StartAcceptorResult("Client Acceptor failed to start", "StartAcceptor", DateTime.Now, false); return(AcceptorResult); } }
public bool StartServer() { MyServer = new Server(Controller.GetDefaultServerSettings()); StartListenerResult ListenerResult = MyServer.StartListener(); if (ListenerResult.IsOperationSuccess) { Controller.Update(new LogModel(ListenerResult.Message, "Networking", DateTime.Now, LogColors.OnNews)); StartAcceptorResult AcceptorResult = MyServer.StartAcceptor(); if (AcceptorResult.IsOperationSuccess) { Controller.Update(new LogModel(AcceptorResult.Message, "Networking", DateTime.Now, LogColors.OnNews)); MyPacketRegister = new PacketRegister(MyServer.PacketManager); MyPacketRegister.RegisterUserPackets(); MyServer.LoadBlackListedIPS(); MyServer.OnClientConnect += MyServer_OnClientConnect; MyServer.OnClientDisconnect += Server_OnClientDisconnect; MyServer.OnClientAuthenticated += Server_OnClientVerified; MyServer.OnClientReceive += Server_OnClientReceive; MyServer.OnClientSend += Server_OnClientSend; MyServer.OnClientBlackList += Server_OnConnectionBlackList; MyServer.OnException += Server_OnException; return(true); } else { Controller.Update(new LogModel(AcceptorResult.Message, "Networking", DateTime.Now, LogColors.OnError)); return(false); } } else { Controller.Update(new LogModel(ListenerResult.Message, "Networking", DateTime.Now, LogColors.OnError)); } return(false); }