コード例 #1
0
        /// <summary>
        /// Accepts incoming npc service connection.
        /// </summary>
        /// <param name="s">Accepted <see cref="Socket"/> object.</param>
        internal static void AcceptConnection(Socket s)
        {
            if (s == null || !s.Connected)
            {
                return;
            }

            if (!Active)
            {
                NetworkHelper.RemoteServiceInfo info = NetworkHelper.GetServiceInfo(s);

                if (info.ServiceType == ServiceType.NpcService)
                {
                    m_NpcServerConnection = new InnerNetworkClient(info.ServiceId, info.ServiceType, s);

                    NpcServiceRequestsHandlers nsrh = new NpcServiceRequestsHandlers(ref m_NpcServerConnection);
                    //m_NpcServerConnection.OnDisconnected += new OnDisconnectedEventHandler(NpcServerConnection_OnDisconnected);
                    m_NpcServerConnection.HandleDelegate = nsrh.Handle;
                    m_NpcServerConnection.Send(new InitializeResponse(Settings.Default.ServiceUniqueID, ( byte )ServiceType.GameService, InitializeResponse.Accepted).ToPacket());

                    Active = true;

                    Logger.WriteLine(Source.InnerNetwork, "Connection accepted for {0} (0x{1})", info.ServiceType, info.ServiceId.ToString("x2"));
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets <see cref="RemoteServiceSettings"/> to specified service.
 /// </summary>
 /// <param name="settings"><see cref="RemoteServiceSettings"/> object to set as settings.</param>
 internal static void SetServiceSettings(RemoteServiceSettings settings)
 {
     if (settings != null && m_ActiveConnections.ContainsKey(settings.ServiceUniqueID))
     {
         InnerNetworkClient client = m_ActiveConnections[settings.ServiceUniqueID];
         client.RemoteServiceSettings = settings;
         client.Send
         (
             new SetSettingsResponse(SetSettingsResponse.Accepted).ToPacket()
         );
         m_ActiveConnections[settings.ServiceUniqueID] = client;
         Logger.WriteLine(Source.InnerNetwork, "{0} (0x{1}) settings update done.", client.ServiceType, client.ServiceID.ToString("x2"));
     }
 }
コード例 #3
0
        /// <summary>
        /// Closes existing client to remote service.
        /// </summary>
        /// <param name="remoteServiceId">Remote service unique id.</param>
        internal static void CloseConnection(byte remoteServiceId)
        {
            if (m_ActiveConnections != null && m_ActiveConnections.ContainsKey(remoteServiceId))
            {
                InnerNetworkClient client = m_ActiveConnections[remoteServiceId];

                if (client != null)
                {
                    if (client.Connected)
                    {
                        client.CloseConnection();
                    }

                    client = null;
                }

                m_ActiveConnections.Remove(remoteServiceId);
            }
        }
コード例 #4
0
        /// <summary>
        /// Occurs when client to one of active <see cref="InnerNetworkClient"/>s brakes up.
        /// </summary>
        /// <param name="errorCode">Exception code, if aviable.</param>
        /// <param name="client">Disconnected <see cref="NetworkClient"/> object.</param>
        /// <param name="connectionId">Connection id.</param>
        private static void OnRemoteConnectionError(int errorCode, NetworkClient client, byte connectionId)
        {
            InnerNetworkClient disconnected = ( InnerNetworkClient )client;

            if (disconnected != null)
            {
                switch (errorCode)
                {
                case 10054:     // An existing client was forcibly closed by the remote host
                {
                    Logger.WriteLine(Source.InnerNetwork, "Remote {0} (0x{1}) closed current connection it self.", disconnected.ServiceType, disconnected.ServiceID.ToString("x2"));
                    break;
                }

                default:
                {
                    Logger.WriteLine(Source.InnerNetwork, "Remote {0} (0x{1}) closed current connection, error code: {2}.", disconnected.ServiceType, disconnected.ServiceID.ToString("x2"), errorCode);
                    break;
                }
                }

                CloseConnection(disconnected.ServiceID);
            }
        }
コード例 #5
0
        /// <summary>
        /// Serves for connections acceptance.
        /// </summary>
        /// <param name="socket">Accepted <see cref="Socket"/>.</param>
        internal static void AcceptConnection(Socket socket)
        {
            if (socket == null || !socket.Connected)
            {
                return;
            }

            NetworkHelper.RemoteServiceInfo info = NetworkHelper.GetServiceInfo(socket);

            if (info.ServiceType == ServiceType.Undefined)
            {
                Console.WriteLine("Connection rejected for remote connection from {0}, service was not recognized.", socket.RemoteEndPoint);
                NetworkHelper.CloseSocket(ref socket);
                return;
            }

            if (m_ActiveConnections.ContainsKey(info.ServiceId))
            {
                Console.WriteLine("{0} with id 0x{1} already connected, skipping connection request.", info.ServiceType, info.ServiceId);
                NetworkHelper.CloseSocket(ref socket);
                return;
            }

            InnerNetworkClient client = null;

            switch (info.ServiceType)
            {
            case ServiceType.LoginService:
            {
                client = new InnerNetworkClient(info.ServiceId, info.ServiceType, socket);
                client.OnDisconnected += new OnDisconnectedEventHandler(OnRemoteConnectionError);
                client.HandleDelegate  = new LoginServiceRequestsHandlers(ref client).Handle;

                break;
            }

            case ServiceType.GameService:
            {
                client = new InnerNetworkClient(info.ServiceId, info.ServiceType, socket);
                client.OnDisconnected += new OnDisconnectedEventHandler(OnRemoteConnectionError);
                client.HandleDelegate  = new GameServiceRequestsHandlers(ref client).Handle;
                break;
            }

            case ServiceType.NpcService:
            {
                client = new InnerNetworkClient(info.ServiceId, info.ServiceType, socket, NpcServiceRequestsHandlers.Handle);
                break;
            }

            default:
            {
                throw new InvalidOperationException();
            }
            }

            Logger.WriteLine(Source.InnerNetwork, "Connection accepted for {0} (0x{1})", client.ServiceType, client.ServiceID.ToString("x2"));
            client.Send(m_ResponseAccepted);
            client.BeginReceive();
            m_ActiveConnections.Add(info.ServiceId, client);
        }
コード例 #6
0
 /// <summary>
 /// Initializes new instance of <see cref="NpcServiceRequestsHandlers"/> class.
 /// </summary>
 /// <param name="client">Referenced <see cref="InnerNetworkClient"/> object.</param>
 internal NpcServiceRequestsHandlers(ref InnerNetworkClient client)
 {
     Service = client;
 }
コード例 #7
0
        private static void RunServer()
        {
            Stopwatch sw = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Console.WriteLine("----===== Revolution WorldServer =====----\n\n"
                              + "Copyright (C) 2013 Revolution Team\n\n"
                              + "This program is CLOSE SOURCE project.\n"
                              + "You DON'T have any right's, if you are NOT autor\n"
                              + "or authorized representative of him.\n"
                              + "Using that program without any right's is ILLEGAL\n\n"
                              + "Authors: Jenose, IMaster\n"
                              + "Authorized representative: netgame.in.th\n\n"
                              + "-------------------------------------------");

            Log.Info("Init Services...");
            AccountService     = new AccountService();
            AiService          = new AiService();
            ChatService        = new ChatService();
            ControllerService  = new ControllerService();
            FeedbackService    = new FeedbackService();
            MapService         = new MapService();
            ObserverService    = new ObserverService();
            PlayerService      = new PlayerService();
            TeamService        = new TeamService();
            SkillsLearnService = new SkillsLearnService();
            StatsService       = new StatsService();
            ShopService        = new ShopService();
            StorageService     = new StorageService();
            TeleportService    = new TeleportService();
            VisibleService     = new VisibleService();

            Log.Info("Init Engines...");
            ScriptEngine = new ScriptEngine.ScriptEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();
            Console.WriteLine("\n-------------------------------------------\n");

            GlobalLogic.ServerStart();
            Console.WriteLine("\n-------------------------------------------\n");

            CountryCode = (CountryCode)Enum.Parse(typeof(CountryCode), Settings.Default.COUNTRY_CODE);

            InnerNetworkOpcode.Init();
            OuterNetworkOpcode.Init();

            InnerClient = new InnerNetworkClient("127.0.0.1", 22323);
            InnerClient.BeginConnect();

            foreach (var channel in DataBaseServer.GetServerChannel(Settings.Default.SERVER_ID))
            {
                var OuterNetwork = new OuterNetworkListener("*", channel.port, channel.max_user);
                OuterNetwork.BeginListening();
                OuterNetworks.Add(OuterNetwork);
            }

            InnerNetworkClient.SendAllThread.Start();
            OuterNetworkConnection.SendAllThread.Start();

            sw.Stop();
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("           Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("-------------------------------------------");
        }