コード例 #1
0
 public static void Start(int portNumber)
 {
     if (Clients == null)
     {
         Clients = new List <ClientBase>();
     }
     if ((Listener == null) || ((Listener.LocalEndpoint as IPEndPoint).Port != portNumber))
     {
         if (Listener != null)
         {
             try
             {
                 Listener.Stop();
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(ex.Message);
                 Debug.WriteLine(ex.StackTrace);
             }
         }
         Listener = new TcpListener(IPAddress.Any, portNumber);
     }
     if (!IsListening)
     {
         Listener.Start();
         Listener.BeginAcceptSocket(AcceptSocketCallback, null);
         IsListening = true;
     }
 }
コード例 #2
0
 public void Start()
 {
     Network.Start();
     Listener.Start();
     Listener.BeginAcceptSocket(AcceptClient, null);
     HeartbeatTimer.Change(HeartbeatInterval, HeartbeatInterval);
     Console.WriteLine("Starbound: Listening on " + Listener.LocalEndpoint);
 }
コード例 #3
0
        public static void AcceptSocketCallback(IAsyncResult ar)
        {
            try
            {
                Socket socket = Listener.EndAcceptSocket(ar);
                try
                {
                    if (socket != null)
                    {
                        socket.NoDelay             = true;
                        socket.LingerState.Enabled = false;
                        NetworkClient client = null;

                        (System.Windows.Application.Current).Dispatcher.Invoke((Action) delegate()
                        {
                            try
                            {
                                client = new NetworkClient(socket);
                            }
                            catch (Exception ex)
                            {
                                client = null;
                                Debug.WriteLine(ex.Message);
                                Debug.WriteLine(ex.StackTrace);
                            }
                        });

                        if (client != null)
                        {
                            Clients.Add(client);
                            OnClientAccepted(client);
                            client.Attach();
                        }
                    }
                }
                catch (Exception lex)
                {
                    Debug.WriteLine(lex.Message);
                    Debug.WriteLine(lex.StackTrace);
                }
                finally
                {
                    Listener.BeginAcceptSocket(AcceptSocketCallback, null);
                }
            }
            catch (Exception ex)
            {
                IsListening = false;
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }
コード例 #4
0
        private void AcceptClient(IAsyncResult result)
        {
            var socket = Listener.EndAcceptSocket(result);

            Listener.BeginAcceptSocket(AcceptClient, null);
            Console.WriteLine("New connection from {0}", socket.RemoteEndPoint);
            var client = new StarboundClient(socket);

            lock (ClientLock) Clients.Add(client);
            client.PacketQueue.Enqueue(new ProtocolVersionPacket(ProtocolVersion));
            client.FlushPackets();
            client.Socket.BeginReceive(client.PacketReader.NetworkBuffer, 0, client.PacketReader.NetworkBuffer.Length,
                                       SocketFlags.None, ClientDataReceived, client);
        }
コード例 #5
0
ファイル: Server.cs プロジェクト: sss-software/Mubox
        public static void AcceptSocketCallback(IAsyncResult ar)
        {
            try
            {
                Socket socket = Listener.EndAcceptSocket(ar);
                try
                {
                    if (socket != null)
                    {
                        socket.NoDelay             = true;
                        socket.LingerState.Enabled = false;
                        NetworkClient client = null;

                        (System.Windows.Application.Current).Dispatcher.Invoke((Action) delegate()
                        {
                            try
                            {
                                client = new NetworkClient(socket, Guid.NewGuid().ToString());
                            }
                            catch (Exception ex)
                            {
                                client = null;
                                ex.Log();
                            }
                        });

                        if (client != null)
                        {
                            Clients.Add(client);
                            OnClientAccepted(client);
                            client.Attach();
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    Listener.BeginAcceptSocket(AcceptSocketCallback, null);
                }
            }
            catch (Exception)
            {
                IsListening = false;
            }
        }
コード例 #6
0
        public bool Start()
        {
            HandlerParam handlerParam = null;
            IAsyncResult ar           = null;

            try
            {
                Listener.Start();

                handlerParam = new HandlerParam(EHandlerType.Listener, this);
                if (LOG_ERROR(handlerParam != null))
                {
                    goto Exit0;
                }
                ar = Listener.BeginAcceptSocket(LP.NetModule.Reactor.OnAccept, handlerParam);
                if (LOG_ERROR(ar != null))
                {
                    goto Exit0;
                }
            }
            catch (SocketException e)
            {
                LP.Logger.P_ERR("ErrorCode={0},SocketErrorCode={1}, Message:{2}, StackTrace:{3}",
                                e.ErrorCode, e.SocketErrorCode, e.Message, e.StackTrace);

                if (LOG_ERROR(false))
                {
                    goto Exit0;
                }
            }
            catch (Exception e)
            {
                LPMiniDump.GenerateNormalDump(e);
            }

            return(true);

Exit0:
            return(false);
        }
コード例 #7
0
ファイル: WebServer.cs プロジェクト: git-thinh/limada
        public virtual void StartListen()
        {
            try {
                running = true;
                while (running)
                {
                    // Set the event to nonsignaled state.
                    AllDone.Reset();

                    // Start an asynchronous socket to listen for connections.
                    Trace.WriteLine("Waiting for a connection...");
                    Listener.BeginAcceptSocket(
                        new AsyncCallback(AcceptRequestAsync),
                        Listener);

                    // Wait until a connection is made before continuing.
                    AllDone.WaitOne();
                }
            } catch (Exception e) {
                Trace.WriteLine(e.ToString());
            }
        }
コード例 #8
0
ファイル: ToffeeServer.cs プロジェクト: Joshsora/Toffee
        /// <summary>
        /// Start accepting connections.
        /// </summary>
        public void Start()
        {
            if (!Listening)
            {
                Listener.Start();
                Listening = true;
                Log?.Info("Started listening on port: {0}.", Port);
            }

            try
            {
                if (Listening)
                {
                    Listener.BeginAcceptSocket(OnConnectionAccepted, null);
                }
            }
            catch
            {
                Log?.Error("Stopped listening for connections. (Error occurred!)");
                Stop();
            }
        }
コード例 #9
0
ファイル: WvsGame.cs プロジェクト: Bia10/DestinyFork
        private static void Main(string[] args)
        {
            if (args.Length > 0 && args[0].ToLower() == "setup")
            {
                InitiateGameServerSetup();
            }

            if (args.Length > 0 && args[0].ToLower() != "setup")
            {
                Log.Warn("Arguments found yet none were recognized! Arguments: " + args);

                HaltOnFatalError();
            }

            if (!File.Exists(Application.ExecutablePath + "WvsGame.ini"))
            {
                Log.Warn("Could not find file WvsGame.ini at path: {0}", Application.ExecutablePath);

                if (Log.YesNo("Would you like to initiate setup process for Destiny game server? ", true))
                {
                    InitiateGameServerSetup();
                }
                else
                {
                    Log.Warn("\n Argument setup was not found!" +
                             "\n Neither was found WvsGame.ini!" +
                             "\n And finally you chose not to setup game server!" +
                             "\n What shall i do then? Make a prophecy about your intent?");

                    HaltOnFatalError();
                }
            }

start:
            Clients = new GameClients();

            Log.Entitle("WvsGame v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                // Read game-server settings from ini
                Settings.Initialize(Application.ExecutablePath + "WvsGame.ini");
                // Test connection to database
                Database.Test();
                // Parse thru MaplestoryDB
                Database.Analyze(true);
                // Create key shortcuts
                Shortcuts.Apply();
                // Set auto-reset
                AutoRestartTime = Settings.GetInt("Server/AutoRestartTime");
                Log.Inform("Automatic restart time set to {0} seconds.", AutoRestartTime);
                // Initiate data handler
                DataProvider.Initialize();
                // Success game-server is alive!
                IsAlive = true;
            }
            catch (Exception ex)
            {
                Log.SkipLine();
                Tracer.TraceErrorMessage(ex, "Exception occurred during game-server initialization!");
            }

            if (IsAlive)
            {
                CenterConnectionDone.Reset();

                new Thread(new ThreadStart(GameToCenterServer.Main)).Start();

                CenterConnectionDone.WaitOne();
#if DEBUG
                string linkPath = Path.Combine(Application.ExecutablePath, "LaunchClient.lnk");

                if (File.Exists(linkPath) && WorldID == 0 && ChannelID == 0) //Only for the first WvsGame instance, and only if shortcut exists
                {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process {
                        StartInfo = { FileName = linkPath }
                    };
                    proc.Start();
                }
#endif
            }
            else
            {
                HaltOnFatalError();
            }

            while (IsAlive)
            {
                AcceptDone.Reset();

                try
                {
                    Listener.BeginAcceptSocket(new AsyncCallback(OnAcceptSocket), null);
                }

                catch (Exception ex)
                {
                    Log.SkipLine();
                    Tracer.TraceErrorMessage(ex, "Ex occured in game server!");
                    throw;
                }

                AcceptDone.WaitOne();
            }

            CloseGameServer();

            if (AutoRestartTime > 0) // TODO: fugly rework
            {
                Log.Inform("Attempting auto-restart in {0} seconds.", AutoRestartTime);
                Thread.Sleep(AutoRestartTime * 1000);
                goto start;
            }

            Console.Read();
        }
コード例 #10
0
ファイル: WvsLogin.cs プロジェクト: Bia10/DestinyFork
        private static void Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLower() == "setup" || !File.Exists(Application.ExecutablePath + "WvsLogin.ini"))
            {
                WvsLoginSetup.Run();
            }

            Worlds  = new Worlds();
            Clients = new LoginClients();

            Log.Entitle("Destiny - Login Server v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                Settings.Initialize(Application.ExecutablePath + "WvsLogin.ini");

                Database.Test();
                Database.Analyze(false);

                RequireStaffIP = Settings.GetBool("Server/RequireStaffIP");
                Log.Inform("Staff will{0}be required to connect through a staff IP.", RequireStaffIP ? " " : " not ");

                AutoRegister = Settings.GetBool("Server/AutoRegister");
                Log.Inform("Automatic registration {0}.", AutoRegister ? "enabled" : "disabled");

                RequestPin = Settings.GetBool("Server/RequestPin");
                Log.Inform("Pin will{0}be requested upon login.", RequestPin ? " " : " not ");

                RequestPic = Settings.GetBool("Server/RequestPic");
                Log.Inform("Pic will{0}be requested upon character selection.", RequestPic ? " " : " not ");

                MaxCharacters = Settings.GetInt("Server/MaxCharacters");
                Log.Inform("Maximum of {0} characters per account.", MaxCharacters);

                for (byte i = 0; i < Settings.GetByte("Server/Worlds"); i++)
                {
                    Worlds.Add(new World(i));
                }

                isAlive = true;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            if (IsAlive)
            {
                CenterConnectionDone.Reset();

                new Thread(new ThreadStart(LoginToCenterServer.Main)).Start();

                CenterConnectionDone.WaitOne();
            }
            else
            {
                Log.SkipLine();
                Log.Inform("Could not start server because of errors.");
            }

            while (IsAlive)
            {
                AcceptDone.Reset();
                Listener.BeginAcceptSocket(new AsyncCallback(OnAcceptSocket), null);
                AcceptDone.WaitOne();
            }

            foreach (LoginClient client in Clients)
            {
                client.Stop();
            }

            Dispose();

            Log.SkipLine();
            Log.Warn("Server stopped.");

            Console.Read();
        }