public List <PlayerPOCO> GetFriendList(string ClientID) { List <PlayerPOCO> ListFriend = new List <PlayerPOCO>(); FilterDefinition <BsonDocument> IDFilter = Builders <BsonDocument> .Filter.Eq("_id", new ObjectId(ClientID)); BsonDocument result = PlayersCollection.Aggregate().Match(IDFilter).Lookup("TripleThunder", "Friends", "_id", "FriendsInfo").FirstOrDefault(); BsonArray Friends = result.GetValue("FriendsInfo").AsBsonArray; foreach (BsonDocument ActiveFriend in Friends) { PlayerPOCO FoundPlayer = new PlayerPOCO(); FoundPlayer.ID = ActiveFriend.GetValue("_id").AsObjectId.ToString(); string Name = ActiveFriend.GetValue("Name").AsString; FoundPlayer.Name = Name; ByteWriter BW = new ByteWriter(); BW.AppendString(Name); BW.AppendInt32(ActiveFriend.GetValue("Level").AsInt32); FoundPlayer.Info = BW.GetBytes(); BW.ClearWriteBuffer(); ListFriend.Add(FoundPlayer); } return(ListFriend); }
public PlayerPOCO LogInPlayer(string Login, string Password, string OwnerServerIP, int OwnerServerPort) { FilterDefinition <BsonDocument> LastTimeCheckedFilter = Builders <BsonDocument> .Filter.Eq("Login", Login) & Builders <BsonDocument> .Filter.Eq("Password", Password); BsonDocument FoundPlayerDocument = PlayersCollection.Find(LastTimeCheckedFilter).FirstOrDefault(); if (FoundPlayerDocument == null && PlayersCollection.Find(Builders <BsonDocument> .Filter.Eq("Login", Login)).FirstOrDefault() == null) { BsonDocument document = new BsonDocument { { "Login", Login }, { "Name", Login }, { "CharacterType", "Jack" }, { "OwnerServerIP", "" }, { "OwnerServerPort", 0 }, { "Password", Password }, { "NumberOfFailedConnection", 0 }, { "Equipment", new BsonArray { new BsonDocument { { "Money", 0 }, { "EXP", 0 } } } } }; PlayersCollection.InsertOne(document); FoundPlayerDocument = PlayersCollection.Find(LastTimeCheckedFilter).FirstOrDefault(); } bool LoggedIn = !string.IsNullOrEmpty(FoundPlayerDocument.GetValue("OwnerServerIP").AsString); if (LoggedIn) { return(LogInPlayer(Login + "1", Password, OwnerServerIP, OwnerServerPort)); } else { PlayerPOCO FoundPlayer = new PlayerPOCO(); FoundPlayer.ID = FoundPlayerDocument.GetValue("_id").AsObjectId.ToString(); FoundPlayer.Name = FoundPlayerDocument.GetValue("Name").AsString; UpdatePlayerIsLoggedIn(FoundPlayer.ID, OwnerServerIP, OwnerServerPort); return(FoundPlayer); } }
public PlayerPOCO LogInPlayer(string Login, string Password, string GameServerIP, int GameServerPort) { FilterDefinition <BsonDocument> LastTimeCheckedFilter = Builders <BsonDocument> .Filter.Eq("Login", Login) & Builders <BsonDocument> .Filter.Eq("Password", Password); BsonDocument FoundPlayerDocument = PlayersCollection.Find(LastTimeCheckedFilter).FirstOrDefault(); if (FoundPlayerDocument == null && PlayersCollection.Find(Builders <BsonDocument> .Filter.Eq("Login", Login)).FirstOrDefault() == null) { BsonDocument document = new BsonDocument { { "Login", Login }, { "Name", Login }, { "Level", 1 }, { "Ranking", 1 }, { "License", 1 }, { "Guild", "" }, { "CharacterType", "Jack" }, { "GameServerIP", "" }, { "GameServerPort", 0 }, { "CommunicationServerIP", "" }, { "CommunicationServerPort", 0 }, { "Password", Password }, { "NumberOfFailedConnection", 0 }, { "Equipment", new BsonArray { new BsonDocument { { "Money", 0 }, { "EXP", 0 } } } }, { "Friends", new BsonArray { } } }; PlayersCollection.InsertOne(document); FoundPlayerDocument = PlayersCollection.Find(LastTimeCheckedFilter).FirstOrDefault(); } bool LoggedIn = !string.IsNullOrEmpty(FoundPlayerDocument.GetValue("GameServerIP").AsString); if (LoggedIn) { return(LogInPlayer(Login + "1", Password, GameServerIP, GameServerPort)); } else { PlayerPOCO FoundPlayer = new PlayerPOCO(); FoundPlayer.ID = FoundPlayerDocument.GetValue("_id").AsObjectId.ToString(); string Name = FoundPlayerDocument.GetValue("Name").AsString; FoundPlayer.Name = Name; ByteWriter BW = new ByteWriter(); BW.AppendString(Name); BW.AppendInt32(FoundPlayerDocument.GetValue("Level").AsInt32); FoundPlayer.Info = BW.GetBytes(); BW.ClearWriteBuffer(); UpdatePlayerIsLoggedIn(FoundPlayer.ID, GameServerIP, GameServerPort); return(FoundPlayer); } }