Ejemplo n.º 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"));
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Sends <see cref="Packet"/> to connected service.
 /// </summary>
 /// <param name="p"><see cref="Packet"/> to send.</param>
 internal void Send(Packet p)
 {
     if (Service != null)
     {
         Service.Send(p);
     }
 }
Ejemplo n.º 3
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"));
     }
 }
Ejemplo n.º 4
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);
        }