public bool RegisterPlayer(string username, string password, PlayerConnection connection) { password = SecurePasswordHasher.Hash(password); if (_playerDataManager.Exists(new PlayerDataLoaderArguments(username))) { var packet = new Packet(PacketType.LOGIN_FAIL, ChannelType.UNASSIGNED); packet.Message.Write("Account already exists!"); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); connection.Disconnect("byeFelicia"); return(false); } // Create their player. var descriptor = PlayerDescriptor.Create(username, password); descriptor.MapID = Settings.StartingMap; descriptor.Role = Settings.DefaultRole; var player = new Player(descriptor, connection); _playerDataManager.Save(player.Descriptor); this.AddPlayer(player); // Notify them that they successfully registered. var successPacket = new Packet(PacketType.REGISTER_SUCCESS, ChannelType.UNASSIGNED); player.SendPacket(successPacket, NetDeliveryMethod.Unreliable); return(true); }
public bool RegisterPlayer(string username, string password, PlayerConnection connection) { // Make sure this player isn't already registered. if (File.Exists(Constants.FILEPATH_ACCOUNTS + username + ".acc")) { // Notify the requester that the specified username is already registered. var packet = new Packet(PacketType.REGISTRATION_FAIL, ChannelType.UNASSIGNED); packet.Message.Write("Account already registered!"); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); connection.Disconnect("byeFelicia"); this.EventOccured?.Invoke(this, new SubjectEventArgs("playerRegister", new object[] { false })); return(false); } // Create their player. var descriptor = PlayerDescriptor.Create(username, password); descriptor.MapID = Settings.StartingMap; descriptor.Role = Settings.DefaultRole; var player = new Player(descriptor, connection); player.Save(); _players.Add(player.UniqueID, player); // Notify them that they successfully registered. var successPacket = new Packet(PacketType.REGISTER_SUCCESS, ChannelType.UNASSIGNED); player.SendPacket(successPacket, NetDeliveryMethod.Unreliable); return(true); }
public bool LoginPlayer(string username, string password, PlayerConnection connection) { // Make sure this player isn't already in game. if (_players.Values.Any(player => player.Name == username)) { var packet = new Packet(PacketType.LOGIN_FAIL, ChannelType.UNASSIGNED); packet.Message.Write("Account already logged in!"); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); connection.Disconnect("byeFelicia"); return(false); } if (File.Exists(Constants.FILEPATH_ACCOUNTS + username + ".acc")) { // If we've made it this far, we've confirmed that the requested account is not already logged into. // Let's make sure the password they provided us is valid. var playerDescriptor = PlayerDescriptor.Load(username); // Check to see whether they were lying about that password... if (playerDescriptor != null && password == playerDescriptor.Password) { // Whoa, they weren't lying! // Let's go ahead and grant them access. // First, we'll add them to the list of online players. var player = new Player(playerDescriptor, connection); _players.Add(player.UniqueID, player); // Now we'll go ahead and tell their client to make whatever preperations that it needs to. // We'll also tell them their super duper unique id. var packet = new Packet(PacketType.LOGIN_SUCCESS, ChannelType.UNASSIGNED); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); this.EventOccured?.Invoke(this, new SubjectEventArgs("playerLogin", new object[] { })); return(true); } else { var packet = new Packet(PacketType.LOGIN_FAIL, ChannelType.UNASSIGNED); packet.Message.Write("Incorrect password!"); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); connection.Disconnect("byeFelicia"); return(false); } } else { var packet = new Packet(PacketType.LOGIN_FAIL, ChannelType.UNASSIGNED); packet.Message.Write("Account does not exist!"); connection.SendPacket(packet, NetDeliveryMethod.Unreliable); connection.Disconnect("byeFelicia"); return(false); } }
public Player(PlayerDescriptor descriptor, PlayerConnection connection) { _descriptor = descriptor; _connection = connection; _connection.Player = this; this.State = ActorStates.Idle; this.Descriptor.CollisionBounds = new Rect(16, 52, 16, 20); this.CollisionBody = new CollisionBody(this); _inventory = new Inventory(this); _equipment = new Equipment(this); _networkComponent = new PlayerNetworkComponent(this, connection); _packetHandler = new PlayerPacketHandler(this); _actionProcessor = new ActionProcessor <Player>(this); _eventHandlers = new Dictionary <string, List <Action <EventArgs> > >(); Script script = Engine.Services.Get <ScriptManager>().CreateScript(Constants.FILEPATH_SCRIPTS + "player.py"); _script = script; try { this.Behavior = script.GetVariable <ActorBehaviorDefinition>("BehaviorDefinition"); } catch { } if (this.Behavior == null) { Engine.Services.Get <Logger>().LogEvent("Error hooking player behavior definition.", LogTypes.ERROR, new Exception("Error hooking player behavior definition.")); } else { this.Behavior.OnCreated(this); this.Behavior.EventOccured += this.BehaviorDescriptor_EventOccured; } this.Descriptor.Stats.Changed += (o, args) => { this.NetworkComponent.SendPlayerStats(); }; }