// Removes a guild ID from a player's guild list IEnumerator RemoveGuildFromGuildList(string guildId, string accountId, LobbyPeer requester = null) { // Player online? if (LobbyPlayer.accountIdToLobbyPlayer.ContainsKey(accountId)) { var playerKicked = LobbyPlayer.accountIdToLobbyPlayer[accountId]; // Get guild ID list if (playerKicked.guildList == null) { yield return(GuildsDB.GetGuildList(accountId, data => { if (data == null) { playerKicked.guildList = new GuildList(); } else { playerKicked.guildList = data; } })); } // Remove guild ID from the kicked player's guild ID list playerKicked.guildList.Remove(guildId); // Set guild ID list yield return(GuildsDB.SetGuildList(accountId, playerKicked.guildList)); // Send the kicked player the new guild ID list SendGuildList(playerKicked); // Player offline } else { GuildList guildList = null; // Get guild ID list yield return(GuildsDB.GetGuildList(accountId, data => { guildList = data; })); if (guildList == null) { if (requester != null) { Lobby.RPC("GuildKickError", requester, guildId, accountId); } yield break; } // Remove guild ID from the kicked player's guild ID list guildList.Remove(guildId); // Set guild ID list yield return(GuildsDB.SetGuildList(accountId, guildList)); } }
IEnumerator GuildRepresentRequest(string guildId, bool represent, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); string accountId = player.accountId; // Get guild members from database if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId)) { yield return(GuildsDB.GetGuildMembers(guildId)); } var guildMembers = GameDB.guildIdToGuildMembers[guildId]; var index = guildMembers.FindIndex(o => o.accountId == accountId); if (index == -1) { Lobby.RPC("GuildRepresentError", info.sender, guildId, represent); yield break; } // Get guild ID list if (player.guildList == null) { yield return(GuildsDB.GetGuildList(accountId, data => { if (data == null) { player.guildList = new GuildList(); } else { player.guildList = data; } })); } // Set/unset main guild if (represent) { // Start representing player.guildList.mainGuildId = guildId; } else { // Stop representing if (player.guildList.mainGuildId == guildId) { player.guildList.mainGuildId = ""; } } // Set guild ID list yield return(GuildsDB.SetGuildList(accountId, player.guildList)); Lobby.RPC("GuildRepresentSuccess", info.sender, guildId, represent); }
void GuildListRequest(LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); if (player.guildList == null) { GuildsDB.GetGuildList(player.accountId, data => { if (data == null) { player.guildList = new GuildList(); } else { player.guildList = data; } GuildsServer.SendGuildList(player); }); } else { GuildsServer.SendGuildList(player); } }
// InstantiatePlayer void InstantiatePlayer(uLink.NetworkPlayer networkPlayer, string accountId, string playerName, Vector3 respawnPosition, float cameraYRotation, int partyId) { LogManager.General.Log(string.Format("Instantiating player prefabs for '{0}' with account ID '{1}'", playerName, accountId)); var party = GameServerParty.partyList[partyId]; // Instantiates an avatar for the player connecting to the server // The player will be the "owner" of this object. Read the manual chapter 7 for more // info about object roles: Creator, Owner and Proxy. GameObject obj = uLink.Network.Instantiate( networkPlayer, // Owner proxyPrefab, ownerPrefab, creatorPrefab, respawnPosition, Cache.quaternionIdentity, 0, // Network group accountId // Initial data ); // Player component Player player = obj.GetComponent <Player>(); player.accountId = accountId; networkPlayer.localData = player; // Send name player.networkView.RPC("ReceivePlayerName", uLink.RPCMode.All, playerName); // Async: DB requests if (isTestServer) { // This section is for quick client tests on the test server // Send other players and myself information about stats player.skillBuild = SkillBuild.GetStarterBuild(); player.customization = new CharacterCustomization(); player.networkView.RPC("ReceiveSkillBuild", uLink.RPCMode.All, player.skillBuild); player.networkView.RPC("ReceiveCharacterCustomization", uLink.RPCMode.All, player.customization); player.networkView.RPC("ReceiveCharacterStats", uLink.RPCMode.All, new CharacterStats()); player.networkView.RPC("ReceiveArtifactTree", uLink.RPCMode.All, Jboy.Json.WriteObject(ArtifactTree.GetStarterArtifactTree())); // After the skill build has been sent, switch the attunement player.networkView.RPC("SwitchWeapon", uLink.RPCMode.All, (byte)0); player.networkView.RPC("SwitchAttunement", uLink.RPCMode.All, (byte)0); } else { // Experience / Level ExperienceDB.GetExperience( accountId, data => { uint exp = 0; if (data != null) { exp = data.experience; } player.networkView.RPC("SetExperience", uLink.RPCMode.All, exp); } ); // TODO: We need to wait until this is finished in ApplyCharacterStats // Skill build SkillBuildsDB.GetSkillBuild( accountId, data => { if (data == null) { player.skillBuild = SkillBuild.GetStarterBuild(); } else { player.skillBuild = data; } // Send build player.networkView.RPC("ReceiveSkillBuild", uLink.RPCMode.All, player.skillBuild); // After the build has been sent, switch the attunement player.networkView.RPC("SwitchWeapon", uLink.RPCMode.All, (byte)0); player.networkView.RPC("SwitchAttunement", uLink.RPCMode.All, (byte)0); } ); // Character customization CharacterCustomizationDB.GetCharacterCustomization( accountId, data => { if (data == null) { player.customization = new CharacterCustomization(); } else { player.customization = data; } // Send customization player.networkView.RPC("ReceiveCharacterCustomization", uLink.RPCMode.All, player.customization); } ); // Character stats StartCoroutine(ServerGameDB.GetCharacterStats(player)); // Guild GuildsDB.GetGuildList(accountId, data => { if (data != null) { GuildsDB.GetGuild(data.mainGuildId, guild => { if (guild != null) { player.networkView.RPC("ReceiveMainGuildInfo", uLink.RPCMode.All, guild.name, guild.tag); } }); } }); // Artifacts ArtifactsDB.GetArtifactTree( accountId, data => { if (data == null) { player.artifactTree = ArtifactTree.GetStarterArtifactTree(); } else { player.artifactTree = data; } player.networkView.RPC("ReceiveArtifactTree", uLink.RPCMode.All, Jboy.Json.WriteObject(player.artifactTree)); } ); // Retrieve arena stats var statsBucket = new Bucket("AccountToStats"); statsBucket.Get( accountId, Constants.Replication.Default, (request) => { var statsInDB = request.GetValue <PlayerStats>(); LogManager.General.Log("Queried stats of account '" + accountId + "' successfully (Ranking: " + statsInDB.bestRanking + ")"); // Send ranking player.networkView.RPC("ReceiveBestRanking", uLink.RPCMode.All, statsInDB.bestRanking); }, (request) => { var statsInDB = new PlayerStats(); LogManager.General.Log("Account '" + accountId + "' aka player '" + playerName + "' doesn't have any player stats yet"); // Send ranking player.networkView.RPC("ReceiveBestRanking", uLink.RPCMode.All, statsInDB.bestRanking); } ); } if (GameManager.isArena) { player.networkView.RPC("GameMaxScore", uLink.RPCMode.Owner, gameMode.scoreNeededToWin); } // Layer if (GameManager.isPvP) { player.networkView.RPC("ChangeParty", uLink.RPCMode.All, partyId); player.networkView.RPC("ChangeLayer", uLink.RPCMode.All, party.layer); } else { player.networkView.RPC("ChangeLayer", uLink.RPCMode.All, Config.instance.openWorldPvPLayer); } // Respawn player.networkView.RPC("Respawn", uLink.RPCMode.All, respawnPosition); player.networkView.RPC("SetCameraYRotation", uLink.RPCMode.Owner, cameraYRotation); // On non account restricted servers we start the game instantly if (!GameManager.isArena || isTestServer) { player.networkView.RPC("StartGame", uLink.RPCMode.Owner); GameManager.gameStarted = true; } // Disable encryption in non-ranked games //if(!GameManager.isRankedGame) // uLink.Network.UninitializeSecurity(networkPlayer); }
IEnumerator GuildInvitationResponse(string guildId, bool accepted, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Get guild invitations if (player.guildInvitations == null) { yield return(GuildsDB.GetGuildInvitations(player.accountId, data => { if (data == null) { player.guildInvitations = new List <string>(); } else { player.guildInvitations = data; } })); } if (player.guildInvitations == null) { Lobby.RPC("GuildInvitationResponseError", info.sender, guildId); yield break; } // Were you invited? if (!player.guildInvitations.Contains(guildId)) { Lobby.RPC("GuildInvitationResponseError", info.sender, guildId); yield break; } // Did the player accept the invitation? if (accepted) { // Get guild members from database if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId)) { yield return(GuildsDB.GetGuildMembers(guildId)); } var guildMembers = GameDB.guildIdToGuildMembers[guildId]; guildMembers.Add(new GuildMember(player.accountId, player.name, (byte)GuildMember.Rank.Default)); // Set guild members yield return(GuildsDB.SetGuildMembers(guildId, guildMembers)); // Get guild ID list if (player.guildList == null) { yield return(GuildsDB.GetGuildList(player.accountId, data => { if (data == null) { player.guildList = new GuildList(); } else { player.guildList = data; } })); } // Add to guild ID list player.guildList.Add(guildId); // Set guild ID list yield return(GuildsDB.SetGuildList(player.accountId, player.guildList)); // Notify all guild members SendGuildMemberList(guildId, guildMembers); } // Remove guild from invitation list player.guildInvitations.Remove(guildId); // Set guild invitations yield return(GuildsDB.SetGuildInvitations(player.accountId, player.guildInvitations, data => { if (data == null) { Lobby.RPC("GuildInvitationResponseError", info.sender, guildId); } else { player.guildInvitations = data; Lobby.RPC("GuildInvitationResponseSuccess", info.sender, guildId, accepted); SendGuildList(player); } })); }