IEnumerator SetFriendNote(string friendName, string groupName, string note, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); LogManager.General.Log(string.Format("'{0}' sets friends list note for '{1}' to '{2}'", player.name, friendName, note)); // Find friends group var selectedGroup = player.friends.GetGroupByName(groupName); // Get account ID string friendAccountId = null; yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => { friendAccountId = data; })); // Error getting account ID? if (friendAccountId == null) { Lobby.RPC("SetFriendNotePlayerDoesntExistError", info.sender, friendName); yield break; } // Remove player from the group selectedGroup.friends.Find(friend => friend.accountId == friendAccountId).note = note; // Save friends list in database yield return(FriendsDB.SetFriends( player.accountId, player.friends, null )); }
IEnumerator ClientArtifactEquip(int itemId, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Wait for all actions to execute while (player.artifactsEditingFlag) { yield return(null); } try { var arti = new Artifact(itemId); player.artifactsEditingFlag = true; if (player.artifactTree.AddArtifact(itemId)) { player.artifactInventory.RemoveArtifact(arti); Lobby.RPC("ArtifactEquip", player.peer, itemId); // Save changes yield return(ArtifactsDB.SetArtifactTree( player, player.artifactTree )); yield return(ArtifactsDB.SetArtifactInventory( player, player.artifactInventory )); } } finally { player.artifactsEditingFlag = false; } }
/// <summary> /// Start a new server. /// </summary> bool StartLocal(int tcpPort, int udpPort, string fileName, int lobbyPort, Type type) { // Ensure that everything has been stopped first if (mGame.isActive) { Disconnect(); } // If there is a lobby port, we should set up the lobby server and/or link first. // Doing so will let us inform the lobby that we are starting a new server. if (lobbyPort > 0) { if (type == Type.Tcp) { mLobby = new TcpLobbyServer(); } else { mLobby = new UdpLobbyServer(); } // Start a local lobby server if (mLobby.Start(lobbyPort)) { if (type == Type.Tcp) { mUp.OpenTCP(lobbyPort); } else { mUp.OpenUDP(lobbyPort); } } else { mLobby = null; return(false); } // Create the local lobby link mGame.lobbyLink = new LobbyServerLink(mLobby); } // Start the game server if (mGame.Start(tcpPort, udpPort)) { mUp.OpenTCP(tcpPort); mUp.OpenUDP(udpPort); if (!string.IsNullOrEmpty(fileName)) { mGame.LoadFrom(fileName); } return(true); } // Something went wrong -- stop everything Disconnect(); return(false); }
public async Task OnMessage(LobbyServerConnection connection, object requestData) { var request = (GroupInviteRequest)requestData; var response = new GroupInviteResponse() { ResponseId = request.RequestId, FriendHandle = request.FriendHandle }; connection.SendMessage(response); LobbyServerConnection user = LobbyServer.GetPlayerByHandle(request.FriendHandle); await user.SendMessage(new GroupConfirmationRequest() { //LeaderFullHandle = connection.PlayerInfo.GetHandle(), //LeaderName = connection.PlayerInfo.GetHandle(), ConfirmationNumber = 1234, ExpirationTime = TimeSpan.FromMinutes(1), GroupId = 508, // TODO //JoinerAccountId = connection.PlayerInfo.GetAccountId(), //JoinerName = connection.PlayerInfo.GetHandle(), RequestId = 0, ResponseId = 0, Type = GroupConfirmationRequest.JoinType.Unicode000E }); }
IEnumerator ClientArtifactDiscard(byte level, byte slotId, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Wait for all actions to execute while (player.artifactsEditingFlag) { yield return(null); } try { player.artifactsEditingFlag = true; player.artifactInventory.bags[level].RemoveItemSlot(slotId); Lobby.RPC("ArtifactDiscard", player.peer, level, slotId); // Save changes yield return(ArtifactsDB.SetArtifactTree( player, player.artifactTree )); yield return(ArtifactsDB.SetArtifactInventory( player, player.artifactInventory )); } finally { player.artifactsEditingFlag = false; } }
public async Task OnMessage(LobbyServerConnection connection, object requestData) { ChatNotification notification = (ChatNotification)requestData; //notification.SenderAccountId = connection.PlayerInfo.GetAccountId(); //notification.SenderHandle = connection.PlayerInfo.GetHandle(); await LobbyServer.sendChatAsync(notification, connection); }
IEnumerator ChangePassword(string newPassword, LobbyMessageInfo info) { // Get the account var player = LobbyServer.GetLobbyPlayer(info); // Change name LogManager.General.Log("Player '" + player.name + "' has requested to change its password."); yield return(StartCoroutine(LobbyGameDB.SetPassword(player, newPassword))); }
public async static Task AddFriend(LobbyServerConnection connection, FriendUpdateRequest request) { LobbyServerConnection friend = LobbyServer.GetPlayerByHandle(request.FriendHandle); var friendRequest = new FriendUpdateRequest() { //FriendHandle = connection.PlayerInfo.GetHandle(), //FriendAccountId = connection.PlayerInfo.GetAccountId(), FriendOperation = FriendOperation.Add, RequestId = 0, ResponseId = 0 }; await friend.SendMessage(friendRequest); // Send a "RequestSent" status to the person that wants to add a new friend await connection.SendMessage(new FriendStatusNotification() { FriendList = new Framework.Network.Static.FriendList() { Friends = new Dictionary <long, Framework.Network.Static.FriendInfo>() { { 0, new Framework.Network.Static.FriendInfo() { FriendHandle = request.FriendHandle, FriendAccountId = request.FriendAccountId, FriendStatus = Framework.Constants.Enums.FriendStatus.RequestSent, } } }, IsDelta = true// set this to true to the request to tell the client to not overwrite current friend list } }); // Send a "RequestReceived" status to the person await connection.SendMessage(new FriendStatusNotification() { FriendList = new Framework.Network.Static.FriendList() { Friends = new Dictionary <long, Framework.Network.Static.FriendInfo>() { { 0, new Framework.Network.Static.FriendInfo() { //FriendHandle = connection.PlayerInfo.GetHandle(), //FriendAccountId = connection.PlayerInfo.GetAccountId(), FriendStatus = Framework.Constants.Enums.FriendStatus.RequestReceived, } } }, IsDelta = true // set that this request doesnt have to overwrite friendlist } }); // TODO: SEND FRIENDSTATUSNOTIFICATION WITH STATUS REQUESTSENT }
void ClientInputSettings(string inputSettingsString, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); //LogManager.General.Log("Player '" + player.name + "' sent new input settings"); InputSettings inputSettings = Jboy.Json.ReadObject <InputSettings>(inputSettingsString); SettingsDB.SetInputSettings(player, inputSettings); }
void ClientArtifactTree(string jsonTree, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); //LogManager.General.Log(jsonTree); ArtifactTree tree = Jboy.Json.ReadObject <ArtifactTree>(jsonTree); LogManager.General.Log("Player '" + player.name + "' sent new artifact tree " + tree.ToString()); ArtifactsDB.SetArtifactTree(player, tree); }
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); }
/// <summary> /// Stop everything. /// </summary> void Disconnect() { mGame.Stop(); if (mLobby != null) { mLobby.Stop(); mLobby = null; } mUp.Close(); }
static private void CreateInstance() { GameObject lobby = new GameObject("lobby"); lobby.hideFlags = HideFlags.HideAndDontSave; DontDestroyOnLoad(lobby); _instance = lobby.AddComponent <LobbyServer>(); lobby.AddComponent <ServerList>(); lobby.AddComponent <PlayerManager>(); lobby.AddComponent <AccountManager>(); }
void LeaveQueue(LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Make the player leave the queue if (player.LeaveQueue()) { // Let the player know he left the queue LogManager.General.Log("'" + player.name + "' left the queue"); Lobby.RPC("LeftQueue", player.peer); } }
void ClientCharacterStats(CharacterStats charStats, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); if (!charStats.valid) { LogManager.General.LogWarning("Detected character stat points hack on player '" + player.name + "'"); return; } //LogManager.General.Log("Player '" + player.name + "' sent new character stats " + charStats.ToString()); TraitsDB.SetCharacterStats(player, charStats); }
IEnumerator LeaveInstance(bool gameEnded, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); if (player.inMatch) { LogManager.General.Log("Player '" + player.name + "' returned from a match"); if (gameEnded) { // Send him his new stats LobbyGameDB.GetPlayerStats(player); // Send him his new artifact inventory ArtifactsDB.GetArtifactInventory(player); // Update ranking list cache if (!player.match.updatedRankingList) { RankingsServer.instance.StartRankingListCacheUpdate(player.match); player.match.updatedRankingList = true; } } LeaveMatch(player); } else if (player.inFFA) { // Send him his new stats //StartCoroutine(lobbyGameDB.GetPlayerStats(player)); // Update ranking list cache /*if(!player.match.updatedRankingList) { * RankingsServer.instance.StartRankingListCacheUpdate(player.match); * player.match.updatedRankingList = true; * }*/ LeaveMatch(player); } else if (player.inTown || player.inWorld) { player.gameInstance = null; if (AccountManager.Master.IsLoggedIn(player.peer)) { yield return(AccountManager.Master.LogOut(info.sender).WaitUntilDone()); } } }
IEnumerator GuildKickRequest(string guildId, string accountId, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Does the player have rights to kick if (!Guild.CanKick(guildId, player.accountId)) { Lobby.RPC("GuildKickError", info.sender, guildId, accountId); yield break; } // Kicking is the same as leaving yield return(GuildLeaveRequest(guildId, accountId, info)); }
IEnumerator AddFriend(string friendName, string groupName, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); LogManager.General.Log(string.Format("'{0}' added '{1}' to friend list group '{2}'", player.name, friendName, groupName)); // Find friends group var selectedGroup = player.friends.GetGroupByName(groupName); // Get account ID string friendAccountId = null; yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => { friendAccountId = data; })); // Error getting account ID? if (friendAccountId == null) { Lobby.RPC("FriendAddPlayerDoesntExistError", info.sender, friendName); yield break; } // Trying to add yourself? if (friendAccountId == player.accountId) { Lobby.RPC("FriendAddCantAddYourselfError", info.sender, friendName); yield break; } // Already in friends list? if (!player.friends.CanAdd(friendAccountId)) { Lobby.RPC("FriendAddAlreadyExistsError", info.sender, friendName); yield break; } // Add player to the group selectedGroup.friends.Add(new Friend(friendAccountId)); // Send new friends list player.OnFriendsListLoaded(); // Save friends list in database yield return(FriendsDB.SetFriends( player.accountId, player.friends, null )); }
private void Awake() { if (sInstance != null) { if (sInstance != this) { Destroy(gameObject); } return; } sInstance = this; DontDestroyOnLoad(this); }
IEnumerator CrystalBalanceRequest(LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); yield return(DonationsDB.GetPaymentsList(player.accountId, data => { if (data == null) { Lobby.RPC("ReceiveCrystalBalance", player.peer, player.accountId, 0); } else { Lobby.RPC("ReceiveCrystalBalance", player.peer, player.accountId, (int)(data.balance * 100)); } })); }
private void Btn_host_Click(object sender, EventArgs e) { connected(); btn_lobbyStartGame.Enabled = true; connectedIP = null; connectedPort = int.Parse(txt_hostPort.Text); playerName = txt_hostPlayerName.Text; lbx_lobbyPlayerList.Items.Add($"{playerName}\t\t(HOST)"); setLobbyGameName(txt_hostGameName.Text); lobbyServer = new LobbyServer(txt_hostGameName.Text, connectedPort, this, playerName); lobbyServer.startServer(); }
IEnumerator RemoveFriendsGroup(string groupName, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); LogManager.General.Log(string.Format("'{0}' removed friends group called '{1}'", player.name, groupName)); // Remove it player.friends.RemoveGroup(groupName); // Save friends list in database yield return(FriendsDB.SetFriends( player.accountId, player.friends, null )); }
void JoinFFARequest(byte playersPerTeam, LobbyMessageInfo info) { var player = LobbyServer.GetLobbyPlayer(info); // If the player is in PvP already, ignore the request if (!player.canEnterPvP) { return; } // Start new server if needed LobbyFFA ffaInstance = LobbyFFA.PickFFAInstance(player); // Connect the player once the instance is ready StartCoroutine(player.ConnectToGameInstanceDelayed(ffaInstance)); }
void ClientSkillBuild(SkillBuild build, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // TODO: Check the build for hacks SkillBuildsDB.SetSkillBuild( player.accountId, build, data => { if (data == null) { Lobby.RPC("SkillBuildSaveError", info.sender); } } ); }
void ClientCharacterCustomization(CharacterCustomization custom, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); LogManager.General.Log(string.Format("Account '{0}' sent character customization!", player.account.name)); CharacterCustomizationDB.SetCharacterCustomization( player.accountId, custom, data => { if (data != null) { player.custom = data; Lobby.RPC("ReceiveCharacterCustomization", player.peer, player.accountId, player.custom); } } ); }
void AcceptMatch(bool accept, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); if (player.instanceAwaitingAccept == null) { return; } if (accept) { player.AcceptMatch(); } else { player.DenyMatch(); } }
static void Main(string[] args) { string read = string.Empty; LobbyServer server = new LobbyServer(100); while (server.Socket.IsBound) { read = Console.ReadLine().ToLower(); if (read == "s" || read == "stop") { lock (server) { Console.WriteLine("Server stopped."); server.Dispose(); } } } }
// Sets the player name public static Coroutine SetPlayerName(LobbyPlayer player, string playerName) { return(GameDB.instance.StartCoroutine(GameDB.Set <string>( "AccountToName", player.accountId, playerName, data => { if (data == null) { Lobby.RPC("PlayerNameChangeError", player.peer); } else { player.name = data; Lobby.RPC("ReceivePlayerName", player.peer, player.accountId, player.name); LobbyServer.OnReceivePlayerName(player); } } ))); }
IEnumerator GuildDisbandRequest(string guildId, LobbyMessageInfo info) { LobbyPlayer player = LobbyServer.GetLobbyPlayer(info); // Get guild members from database if (!GameDB.guildIdToGuildMembers.ContainsKey(guildId)) { yield return(GuildsDB.GetGuildMembers(guildId)); } // Does the player have rights to disband? if (!Guild.CanDisband(guildId, player.accountId)) { Lobby.RPC("GuildDisbandError", info.sender, guildId); yield break; } // We checked whether the player has the right to disband the guild. // Now we need to do this: // 1.) Remove the guild from the players' guild list (AccountToGuilds). // 2.) Remove the member list for that guild (GuildToMembers). // 3.) Remove the guild entry itself (Guilds). // 4.) Remove the cache data about that guild (automatically done in 2 and 3). // 1.) Remove the guild from the players' guild list (AccountToGuilds) foreach (GuildMember member in GameDB.guildIdToGuildMembers[guildId]) { // Update guild ID list StartCoroutine(RemoveGuildFromGuildList(guildId, member.accountId, info.sender)); } // 2.) Remove the member list for that guild (GuildToMembers) yield return(GuildsDB.RemoveGuildMembers(guildId)); // 3.) Remove the guild entry itself (Guilds) yield return(GuildsDB.RemoveGuild(guildId)); // Notify the player who requested it Lobby.RPC("GuildDisbandSuccess", info.sender, guildId); }
IEnumerator GuildInvitationsListRequest(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; } })); } Lobby.RPC("ReceiveGuildInvitationsList", player.peer, player.guildInvitations.ToArray(), true); }