Ejemplo n.º 1
0
 private void ProcessClientDisconnectPacket(ClientDisconnectPacket packet)
 {
     AsyncJavascriptCallback("DisconnectFromServerWithReason_Callback", packet.Reason);
 }
Ejemplo n.º 2
0
        private void ProcessUsernamePacket(UsernamePacket packet)
        {
            // Check the user's authorization with the master server. If not authorized, connection will be denied.
            bool isAuthorized = WebUtility.IsUserAuthorizedForServer(Model.ServerPort, packet.Username);

            if (isAuthorized)
            {
                if(Model.BannedUsersList.Contains(packet.Username))
                {
                    ClientDisconnectPacket response = new ClientDisconnectPacket("You have been BANNED from this server.");
                    Agent.SendPacket(response, packet.SenderConnection, NetDeliveryMethod.ReliableUnordered);
                    packet.SenderConnection.Disconnect("You have been BANNED from this server.");
                }
                else
                {
                    if (!Model.ConnectionUsernamesDictionary.ContainsKey(packet.SenderConnection))
                    {
                        Model.ConnectionUsernamesDictionary.Add(packet.SenderConnection, packet.Username);
                        Model.LogMessages.Add(packet.Username + " (" + packet.SenderConnection.RemoteEndPoint.Address.ToString() + ") has joined the server.");
                    }
                    SendContentPackageList(packet.SenderConnection);
                }

            }
            else
            {
                Model.LogMessages.Add("Denied user '" + packet.Username + "' from connecting. User failed master server authorization.");
                ClientDisconnectPacket response = new ClientDisconnectPacket("Failed to authenticate with master server.");
                Agent.SendPacket(response, packet.SenderConnection, NetDeliveryMethod.ReliableUnordered);
            }
        }