Example #1
0
        internal static void Route(JamServerConnection serverConnection, JamPacket packet)
        {
            JamServer server    = serverConnection.Server;
            Guid      recipient = packet.Header.Receipient;

            if (recipient == Guid.Empty)
            {
                InternalServerInterpreter.Interpret(serverConnection, packet);
                return;
            }

            JamServerConnection recipientConnection = server.GetConnection(recipient);

            if (recipientConnection == null)
            {
                server.OnUndelieveredMessageReceived(new JamServer.MessageReceivedEventArgs()
                {
                    ServerConnection = serverConnection, Packet = packet
                });
            }
            else
            {
                recipientConnection.Send(packet);
            }
        }
        internal static void Interpret(JamServerConnection serverConnection, JamPacket packet)
        {
            switch (packet.Header.DataType)
            {
            case LoginRequest.DATA_TYPE:
                serverConnection.RespondToLogin(packet);
                break;

            case PingRequest.DATA_TYPE:
                serverConnection.RespondToPing(packet);
                break;

            default:
                serverConnection.Server.OnMessageReceived(new JamServer.MessageReceivedEventArgs()
                {
                    ServerConnection = serverConnection, Packet = packet
                });
                break;
            }
        }
Example #3
0
        public void RespondToLogin(JamPacket loginPacket)
        {
            if (loginPacket.Header.DataType != LoginRequest.DATA_TYPE)
            {
                return;
            }

            LoginRequest request = new LoginRequest(loginPacket.Data, Serializer);

            LoginResponse response;

            try
            {
                Account      = AccountFactory.Authenticate(request.Username, request.Password, Server.HashFactory);
                AppSigniture = request.AppSigniture;
                Server.OnClientIdentified(new JamServer.IdentifiedConnectionEventArgs()
                {
                    ServerConnection = this, RemoteEndPoint = Client.Client.RemoteEndPoint, Account = Account
                });

                JamServerConnection existingConnection = Server.GetConnection(Account.AccountID);
                if (existingConnection != null)
                {
                    Server.OnClientConnectedElsewhere(new JamServer.IdentifiedConnectionEventArgs()
                    {
                        ServerConnection = this, RemoteEndPoint = existingConnection.Client.Client.RemoteEndPoint, Account = existingConnection.Account
                    });
                    existingConnection.Dispose();
                }

                JamServerConnection appServiceConnection = Server.GetAppServiceConnection(AppSigniture);
                if (appServiceConnection == null && AppSigniture != Server.AppSigniture)
                {
                    response = new LoginResponse(LoginResponse.LoginResult.AppOffline, null, Guid.Empty, Serializer);
                    Server.OnClientOfflineAppRequest(new JamServer.IdentifiedConnectionEventArgs()
                    {
                        ServerConnection = this, RemoteEndPoint = Client.Client.RemoteEndPoint, Account = Account
                    });
                }
                else
                {
                    Guid appServiceID = Guid.Empty;
                    if (appServiceConnection != null)
                    {
                        appServiceID = appServiceConnection.Account.AccountID;
                    }

                    response = new LoginResponse(LoginResponse.LoginResult.Good, Account, appServiceID, Serializer);
                    Server.AddConnection(this);
                }
            }
            catch (AccountFactory.InvalidUsernameException)
            {
                response = new LoginResponse(LoginResponse.LoginResult.BadUsername, null, Guid.Empty, Serializer);
                Server.OnClientInvalidUsername(new JamServer.ConnectionEventArgs()
                {
                    ServerConnection = this, RemoteEndPoint = Client.Client.RemoteEndPoint
                });
            }
            catch (AccountFactory.InvalidAccessCodeException)
            {
                response = new LoginResponse(LoginResponse.LoginResult.BadPassword, null, Guid.Empty, Serializer);
                Server.OnClientInvalidPassword(new JamServer.ConnectionEventArgs()
                {
                    ServerConnection = this, RemoteEndPoint = Client.Client.RemoteEndPoint
                });
            }
            catch (EntityException)
            {
                Server.Dispose();
                return;
            }

            JamPacket responsePacket = new JamPacket(Guid.Empty, Guid.Empty, LoginResponse.DATA_TYPE, response.GetBytes());

            Send(responsePacket);
        }
Example #4
0
        public void DeleteConnection(Guid accountID)
        {
            JamServerConnection connection = GetConnection(accountID);

            connections.Remove(connection);
        }
Example #5
0
 public void AddConnection(JamServerConnection connection)
 {
     connections.Add(connection);
 }