/// <summary> /// Verify a user token and login. /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns>login result</returns> public virtual bool LogIn(string username, string password) { // if already online, deny. if (OnlinePlayers.Any(p => p.Username == username)) { return(false); } if (!PlayerRepository.IsExsist(username)) { return(false); } Player player = PlayerRepository.GetPlayer(username); if (player.Token.ToString() != password) { return(false); } OnlinePlayers.Add(player); Session.Value.Set(player).Exiting += Session_Exiting; LoggedIn?.Invoke(this, player); Logger.Info($"[{username}] login succeed"); return(true); }
public void AddPlayer(Player player) { OnlinePlayers.Add(player); new PlayerListItem(player.Wrapper) { Action = 0, Gamemode = player.Gamemode, Username = player.Username, UUID = player.Uuid }.Broadcast(this); //Send playerlist item to old players & player him self BroadcastExistingPlayers(player.Wrapper); }
public void AddPlayer(Player player) { OnlinePlayers.Add(player.EntityId, player); new PlayerListItem(player.Wrapper) { Action = 0, Gamemode = player.Gamemode, Username = player.Username, Uuid = player.Uuid }.Broadcast(this); //Send playerlist item to old players & player him self IntroduceNewPlayer(player.Wrapper); }
public bool RecvPacket(PacketPlayerJoin p) { if (Identity == null) { Disconnect("Cannot do that without authenticating first!"); return(false); } if (IsPlayerOnline(p.PlayerName)) { Disconnect("Two of the same player on server!"); return(false); } OnlinePlayers.Add(PlayerInstance.GetInstance(p.PlayerName)); return(true); }
/// <summary> /// Handle a player join event /// </summary> private static void HandlePlayerJoin( string text, OutputParseResult outputparseresult, IPlayerAction playeraction) { PlayerActionJoin join = (PlayerActionJoin)playeraction; Player player = new Player(join.PlayerName, join.Ip, join.PlayerName) { JoinTime = @join.Time }; if (!OnlinePlayers.ContainsKey(player.Name)) { OnlinePlayers.Add(player.Name, player); } RaisePlayerListChangedEvent(); }
/// <summary> /// Add a player to the online players list and raise the according events /// </summary> /// <param name="player">The player to add</param> public static void AddPlayer(Player player) { if (player == null || string.IsNullOrEmpty(player.Name)) { return; } try { if (OnlinePlayers.ContainsKey(player.Name)) { return; } OnlinePlayers.Add(player.Name, player); RaisePlayerListAdditionEvent(player); RaisePlayerListChangedEvent(); } catch (Exception exception) { Logger.Log(LogLevel.Severe, "PlayerHandler", "Failed to add player: " + player.Name, exception.Message); } }
private void Initialize() { timerPlayerList = new Timer((sender) => { UpdateOnlinePlayers(sender); }, this, 0, 30000); Players = new PlayersCollection(); Players.OnPlayerJoin = (player) => { if (player == null) { return; } var existing = OnlinePlayers.FirstOrDefault(p => p.NickId.Equals(player.NickId)); if (existing == null) { lock (lockOnlinePlayers) { OnlinePlayers.Add(player); } } else { existing.Country = player.Country; } }; Players.OnPlayerLeave = (player) => { if (player == null) { lock (lockOnlinePlayers ) { OnlinePlayers.RemoveAll(p => p.NickId.Equals(player.NickId)); } } }; GameObjects = new GameObjectsCollection(); AirFields = new AirFieldCollection(); CoalitionIndexes = new List <CoalitionIndex>(); }
private void OnRecvPlayerEnter(IChannel channel, Message message) { CPlayerEnter request = message as CPlayerEnter; Player player = (Player)channel.GetContent(); Scene scene = World.Instance.GetScene(player.scene); // add the player to the scene player.Spawn(); scene.AddEntity(player); // send player attributes SPlayerAttribute attrMessage = new SPlayerAttribute() { playerId = player.entityId, name = player.user, currentHP = player.currentHP, level = player.level, intelligence = player.intelligence, speed = player.speed, attack = player.attack, defense = player.defense, GoldNum = player.GoldNum, SilverNum = player.SilverNum }; channel.Send(attrMessage); // add online player OnlinePlayers.Add(player.user, player); // send oneline player to frontend Dictionary <int, string> SendDic = new Dictionary <int, string>(); foreach (KeyValuePair <string, Player> tmp in OnlinePlayers) { SendDic.Add(tmp.Value.entityId, tmp.Key); Console.WriteLine("contains user:{0}", tmp.Key); } SFindFriends response = new SFindFriends() { friends = SendDic }; player.Broadcast(response); // send treasure attributes ConnectDB connect = new ConnectDB(); if (treasureAttributes.Count == 0) { treasureAttributes = new Dictionary <string, DTreasure>(connect.GetTreasureAttri()); } STreasureAttribute treasureAttribute = new STreasureAttribute() { treasureAttri = new Dictionary <string, DTreasure>(treasureAttributes) }; channel.Send(treasureAttribute); // send mall if (backMall.Count == 0) { backMall = new Dictionary <string, DTreasureMall>(connect.DBGetMall()); } SMall mall = new SMall() { goods = new Dictionary <string, DTreasureMall>(backMall) }; channel.Send(mall); // send package SPackage package = new SPackage() { goods = new Dictionary <string, DTreasurePackage>(connect.DBGetPackage(player.user)) }; channel.Send(package); // send friends SFriends friendList = new SFriends() { friends = new List <string>(connect.GetFriends(player.user)) }; channel.Send(friendList); // send friend requests SFindFriendRequests requestList = new SFindFriendRequests() { requests = new List <string>(connect.GetFriendRequest(player.user)) }; channel.Send(requestList); }
private void UpdateOnlinePlayers(object sender) { bool playerListChanged = false; var server = sender as Server; if (sender == null || !server.IsRconConnected || Rcon == null) { return; } var newList = Rcon.GetPlayerList().With(list => list.Where(p => p != null)); if (newList == null) { return; } if (newList.Count() == 0) { lock (server.lockOnlinePlayers) OnlinePlayers.Clear(); if (OnPlayerListChange != null) { OnPlayerListChange(OnlinePlayers.ToList(), this); } return; } HashSet <Guid> onlineIds = new HashSet <Guid> (newList.Select(player => player.NickId)); lock (server.lockOnlinePlayers) { playerListChanged = OnlinePlayers.Count(p => !onlineIds.Contains(p.NickId)) > 0; OnlinePlayers.RemoveAll(player => !onlineIds.Contains(player.NickId)); foreach (var player in newList) { var existing = OnlinePlayers.FirstOrDefault(p => p.NickId.Equals(player.NickId)); if (existing == null) { OnlinePlayers.Add(player); playerListChanged = true; } else { if (!playerListChanged) { playerListChanged = existing.Ping != player.Ping || existing.Status != player.Status || existing.CoalitionIndex != player.CoalitionIndex; } existing.Ping = player.Ping; existing.Status = player.Status; existing.ClientId = player.ClientId; existing.CoalitionIndex = player.CoalitionIndex; } } if (playerListChanged && OnPlayerListChange != null) { OnPlayerListChange(OnlinePlayers.ToList(), this); } } }