예제 #1
0
        /// <summary>
        ///     Retrieves a list of users in a channel
        /// </summary>
        public void GetUsersInChannel(string channel, ChatUsersCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(new List <string>(), "Not connected");
                return;
            }

            connection.SendMessage((short)MsfOpCodes.GetUsersInChannel, channel, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(new List <string>(), response.AsString("Unknown error"));
                    return;
                }

                var list = new List <string>().FromBytes(response.AsBytes());

                callback.Invoke(list, null);
            });
        }
예제 #2
0
        /// <summary>
        /// Gets account information of a client, who is connected to master server,
        /// and who's peer id matches the one provided
        /// </summary>
        public void GetPeerAccountInfo(int peerId, PeerAccountInfoCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected to server");
                return;
            }

            connection.SendMessage((short)MsfOpCodes.GetPeerAccountInfo, peerId, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown error"));
                    return;
                }

                var data = response.Deserialize(new PeerAccountInfoPacket());

                callback.Invoke(data, null);
            });
        }
예제 #3
0
        /// <summary>
        /// Sets lobby properties of a specified lobby id
        /// </summary>
        public void SetLobbyProperties(int lobbyId, Dictionary <string, string> properties,
                                       SuccessCallback callback, IClientSocket connection)
        {
            var packet = new LobbyPropertiesSetPacket()
            {
                LobbyId    = lobbyId,
                Properties = properties
            };

            connection.SendMessage((short)MsfOpCodes.SetLobbyProperties, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
        /// <summary>
        /// Retrieves lobby member data of user, who has connected to master server with
        /// a specified peerId
        /// </summary>
        public void GetMemberData(string lobbyId, int peerId, LobbyMemberDataCallback callback, IClientSocket connection)
        {
            var packet = new IntPairPacket
            {
                A = lobbyId,
                B = peerId
            };

            connection.SendMessage((short)MsfOpCodes.GetLobbyMemberData, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown error"));
                    return;
                }

                var memberData = response.Deserialize(new LobbyMemberData());
                callback.Invoke(memberData, null);
            });
        }
예제 #5
0
파일: MstChatClient.cs 프로젝트: poup/MST
        /// <summary>
        /// Retrieves a list of channels, which user has joined
        /// </summary>
        public void GetMyChannels(ChatChannelsCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(new List <ChatChannelInfo>(), "Not connected");
                return;
            }

            connection.SendMessage((short)MstMessageCodes.GetCurrentChannels, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(new List <ChatChannelInfo>(), response.AsString("Unknown error"));
                    return;
                }

                var data = response.Deserialize(new ChatChannelsListPacket());
                callback.Invoke(data.Channels, null);
            });
        }
예제 #6
0
        private IEnumerator KeepSendingUpdates(IClientSocket connection)
        {
            while (true)
            {
                yield return(new WaitForSeconds(ProfileUpdatesInterval));

                if (modifiedProfilesList.Count == 0)
                {
                    continue;
                }

                using (var ms = new MemoryStream())
                {
                    using (var writer = new EndianBinaryWriter(EndianBitConverter.Big, ms))
                    {
                        // Write profiles count
                        writer.Write(modifiedProfilesList.Count);

                        foreach (var profile in modifiedProfilesList)
                        {
                            // Write userId
                            writer.Write(profile.UserId);

                            var updates = profile.GetUpdates();

                            // Write updates length
                            writer.Write(updates.Length);

                            // Write updates
                            writer.Write(updates);

                            profile.ClearUpdates();
                        }

                        connection.SendMessage((short)MstMessageCodes.UpdateServerProfile, ms.ToArray());
                    }
                }

                modifiedProfilesList.Clear();
            }
        }
        /// <summary>
        /// Tries to get an access to a room with a given room id, password,
        /// and some other properties, which will be visible to the room (game server)
        /// </summary>
        public void GetAccess(int roomId, RoomAccessCallback callback, string password,
                              Dictionary <string, string> properties, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            var packet = new RoomAccessRequestPacket()
            {
                RoomId     = roomId,
                Properties = properties,
                Password   = password
            };

            connection.SendMessage((short)MsfOpCodes.GetRoomAccess, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var access = response.Deserialize(new RoomAccessPacket());

                LastReceivedAccess = access;

                callback.Invoke(access, null);

                if (AccessReceived != null)
                {
                    AccessReceived.Invoke(access);
                }

                if (RoomConnector.Instance != null)
                {
                    RoomConnector.Connect(access);
                }
            });
        }
예제 #8
0
        /// <summary>
        /// Sends a request to abort spawn request, which was not yet finalized
        /// </summary>
        public void AbortSpawn(int spawnId, AbortSpawnHandler callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback?.Invoke(false, "Not connected");
                return;
            }

            connection.SendMessage((short)MsfMessageCodes.AbortSpawnRequest, spawnId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback?.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                Logs.Debug($"Room process [{spawnId}] was successfuly aborted");

                callback?.Invoke(true, null);
            });
        }
예제 #9
0
        /// <summary>
        /// Sends a new password to server
        /// </summary>
        public void ChangePassword(MstProperties data, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected to server");
                return;
            }

            connection.SendMessage((short)MstMessageCodes.ChangePassword, data.ToBytes(), (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);

                OnPasswordChangedEvent?.Invoke();
            });
        }
예제 #10
0
        /// <summary>
        ///     Retrieves a list of public games, which pass a provided filter.
        ///     (You can implement your own filtering by extending modules or "classes"
        ///     that implement <see cref="IGamesProvider" />)
        /// </summary>
        public void FindGames(Dictionary <string, string> filter, FindGamesCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                Logs.Error("Not connected");
                callback.Invoke(new List <GameInfoPacket>());
                return;
            }

            connection.SendMessage((short)MsfOpCodes.FindGames, filter.ToBytes(), (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    Logs.Error(response.AsString("Unknown error while requesting a list of games"));
                    callback.Invoke(new List <GameInfoPacket>());
                    return;
                }

                var games = response.DeserializeList(() => new GameInfoPacket()).ToList();

                callback.Invoke(games);
            });
        }
예제 #11
0
        /// <summary>
        /// Sends a generic login request
        /// </summary>
        public void LogIn(Dictionary <string, string> data, LoginCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected to server");
                return;
            }

            _isLogginIn = true;

            // We first need to get an aes key
            // so that we can encrypt our login data
            Msf.Security.GetAesKey(aesKey => {
                if (aesKey == null)
                {
                    _isLogginIn = false;
                    callback.Invoke(null, "Failed to log in due to security issues");
                    return;
                }

                var encryptedData = Msf.Security.EncryptAES(data.ToBytes(), aesKey);

                connection.SendMessage((short)CustomMasterServerMSG.login, encryptedData, (status, response) => {
                    _isLogginIn = false;

                    if (status != ResponseStatus.Success)
                    {
                        callback.Invoke(null, response.AsString("Unknown error"));
                        return;
                    }

                    IsLoggedIn = true;

                    AccountInfo = response.Deserialize(new AccountInfoPacket());
                    callback.Invoke(AccountInfo, null);
                });
            }, connection);
        }
예제 #12
0
        /// <summary>
        ///     Updates the options of the registered room
        /// </summary>
        public void SaveOptions(int roomId, RoomOptions options, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

            var changePacket = new SaveRoomOptionsPacket {
                Options = options,
                RoomId  = roomId
            };

            connection.SendMessage((short)MsfOpCodes.SaveRoomOptions, changePacket, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown Error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
예제 #13
0
        /// <summary>
        ///     Sends a request to create a lobby, using a specified factory
        /// </summary>
        public void CreateLobby(string factory, Dictionary <string, string> properties,
                                CreateLobbyCallback calback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                calback.Invoke(null, "Not connected");
                return;
            }

            properties[MsfDictKeys.LobbyFactoryId] = factory;

            connection.SendMessage((short)MsfOpCodes.CreateLobby, properties.ToBytes(), (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    calback.Invoke(null, response.AsString("Unknown error"));
                    return;
                }

                var lobbyId = response.AsInt();

                calback.Invoke(lobbyId, null);
            });
        }
예제 #14
0
        /// <summary>
        /// Sends a request to create a lobby, using a specified factory
        /// </summary>
        public void CreateLobby(string factory, MstProperties options, CreateLobbyCallback calback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                calback.Invoke(null, "Not connected");
                return;
            }

            options.Set(MstDictKeys.lobbyFactoryId, factory);

            connection.SendMessage((short)MstMessageCodes.CreateLobby, options.ToBytes(), (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    calback.Invoke(null, response.AsString("Unknown error"));
                    return;
                }

                var lobbyId = response.AsInt();

                calback.Invoke(lobbyId, null);
            });
        }
예제 #15
0
        /// <summary>
        /// Sends a request to get access to room, which is assigned to this lobby
        /// </summary>
        public void GetLobbyRoomAccess(Dictionary <string, string> properties, RoomAccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            connection.SendMessage((short)MstMessageCodes.GetLobbyRoomAccess, properties.ToBytes(), (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var access = response.Deserialize(new RoomAccessPacket());

                Mst.Client.Rooms.TriggerAccessReceivedEvent(access);

                callback.Invoke(access, null);
            });
        }
예제 #16
0
        /// <summary>
        /// Sends a request to join a lobby
        /// </summary>
        public void JoinLobby(int lobbyId, JoinLobbyCallback callback, IClientSocket connection)
        {
            // Send the message
            connection.SendMessage((short)MstMessageCodes.JoinLobby, lobbyId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                var data = response.Deserialize(new LobbyDataPacket());

                var key = data.LobbyId + ":" + connection.Peer.Id;

                if (joinedLobbies.ContainsKey(key))
                {
                    // If there's already a lobby
                    callback.Invoke(joinedLobbies[key], null);
                    return;
                }

                var joinedLobby = new JoinedLobby(data, connection);

                LastJoinedLobby = joinedLobby;

                // Save the lobby
                joinedLobbies[key] = joinedLobby;

                callback.Invoke(joinedLobby, null);

                if (OnLobbyJoinedEvent != null)
                {
                    OnLobbyJoinedEvent.Invoke(joinedLobby);
                }
            });
        }
예제 #17
0
        /// <summary>
        /// Sends a request to server, retrieves all profile values, and applies them to a provided
        /// profile
        /// </summary>
        public void FillProfileValues(ObservableServerProfile profile, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

            connection.SendMessage((short)MstMessageCodes.ServerProfileRequest, profile.UserId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                // Use the bytes received, to replicate the profile
                profile.FromBytes(response.AsBytes());

                // Clear all updates if exist
                profile.ClearUpdates();

                // Add profile to list
                profilesList[profile.UserId] = profile;

                // Register listener for modified
                profile.OnModifiedInServerEvent += serverProfile =>
                {
                    OnProfileModified(profile, connection);
                };

                // Register to dispose event
                profile.OnDisposedEvent += OnProfileDisposed;

                callback.Invoke(true, null);
            });
        }
예제 #18
0
        /// <summary>
        /// Sends a request to abort spawn request, which was not yet finalized
        /// </summary>
        /// <param name="spawnTaskId"></param>
        /// <param name="callback"></param>
        /// <param name="connection"></param>
        public void AbortSpawn(int spawnTaskId, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback?.Invoke(false, "Not connected");
                return;
            }

            Logs.Debug($"Aborting process [{spawnTaskId}]");

            connection.SendMessage((short)MstMessageCodes.AbortSpawnRequest, spawnTaskId, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    Logs.Error($"An error occurred when abort request [{response.AsString()}]");
                    callback?.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                Logs.Debug($"Room process [{spawnTaskId}] was successfuly aborted");

                callback?.Invoke(true, null);
            });
        }
예제 #19
0
        /// <summary>
        ///     This method should be called, when spawn process is finalized (finished spawning).
        ///     For example, when spawned game server fully starts
        /// </summary>
        public void FinalizeSpawnedProcess(int spawnId, Dictionary <string, string> finalizationData,
                                           CompleteSpawnedProcessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

            var packet = new SpawnFinalizationPacket {
                SpawnId          = spawnId,
                FinalizationData = finalizationData
            };

            connection.SendMessage((short)MsfOpCodes.CompleteSpawnProcess, packet, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown Error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
예제 #20
0
        /// <summary>
        ///     Sends a request to master server, to see if a given token is valid
        /// </summary>
        public void ValidateAccess(int roomId, string token, RoomAccessValidateCallback callback,
                                   IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected");
                return;
            }

            var packet = new RoomAccessValidatePacket {
                RoomId = roomId,
                Token  = token
            };

            connection.SendMessage((short)MsfOpCodes.ValidateRoomAccess, packet, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(null, response.AsString("Unknown Error"));
                    return;
                }

                callback.Invoke(response.Deserialize(new UsernameAndPeerIdPacket()), null);
            });
        }
예제 #21
0
        /// <summary>
        ///     Sends a request to server, to ask for an e-mail confirmation code
        /// </summary>
        public void RequestEmailConfirmationCode(SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected to server");
                return;
            }

            if (!IsLoggedIn)
            {
                callback.Invoke(false, "You're not logged in");
                return;
            }

            connection.SendMessage((short)MsfOpCodes.RequestEmailConfirmCode, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
예제 #22
0
        /// <summary>
        ///     Sends a new password to server
        /// </summary>
        public void ChangePassword(PasswordChangeData data, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected to server");
                return;
            }

            var dictionary = new Dictionary <string, string> {
                { "email", data.Email },
                { "code", data.Code },
                { "password", data.NewPassword }
            };

            connection.SendMessage((short)MsfOpCodes.PasswordChange, dictionary.ToBytes(), (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
예제 #23
0
 /// <summary>
 /// Current player sends a chat message to lobby
 /// </summary>
 public void SendChatMessage(string message, IClientSocket connection)
 {
     connection.SendMessage((short)MstMessageCodes.LobbySendChatMessage, message);
 }
예제 #24
0
 /// <summary>
 /// Set's lobby user properties (current player sets his own properties,
 ///  which can be accessed by game server and etc.)
 /// </summary>
 public void SetMyProperties(MstProperties properties, SuccessCallback callback, IClientSocket connection)
 {
     connection.SendMessage((short)MstMessageCodes.SetMyLobbyProperties, properties.ToBytes(), Mst.Create.SuccessCallback(callback));
 }
예제 #25
0
        /// <summary>
        /// Sends a generic login request
        /// </summary>
        public void SignIn(MstProperties data, SignInCallback callback, IClientSocket connection)
        {
            Logs.Debug("Signing in...");

            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected to server");
                return;
            }

            IsNowSigningIn = true;

            // We first need to get an aes key
            // so that we can encrypt our login data
            Mst.Security.GetAesKey(aesKey =>
            {
                if (aesKey == null)
                {
                    IsNowSigningIn = false;
                    callback.Invoke(null, "Failed to log in due to security issues");
                    return;
                }

                var encryptedData = Mst.Security.EncryptAES(data.ToBytes(), aesKey);

                connection.SendMessage((short)MstMessageCodes.SignIn, encryptedData, (status, response) =>
                {
                    IsNowSigningIn = false;

                    if (status != ResponseStatus.Success)
                    {
                        ClearAuthToken();

                        callback.Invoke(null, response.AsString("Unknown error"));
                        return;
                    }

                    // Parse account info
                    var accountInfoPacket = response.Deserialize(new AccountInfoPacket());

                    AccountInfo = new ClientAccountInfo()
                    {
                        Id               = accountInfoPacket.Id,
                        Username         = accountInfoPacket.Username,
                        Email            = accountInfoPacket.Email,
                        PhoneNumber      = accountInfoPacket.PhoneNumber,
                        Facebook         = accountInfoPacket.Facebook,
                        Token            = accountInfoPacket.Token,
                        IsAdmin          = accountInfoPacket.IsAdmin,
                        IsGuest          = accountInfoPacket.IsGuest,
                        IsEmailConfirmed = accountInfoPacket.IsEmailConfirmed,
                        Properties       = accountInfoPacket.Properties,
                    };

                    // If RememberMe is checked on and we are not guset, then save auth token
                    if (RememberMe && !AccountInfo.IsGuest && !string.IsNullOrEmpty(AccountInfo.Token))
                    {
                        SaveAuthToken(AccountInfo.Token);
                    }
                    else
                    {
                        ClearAuthToken();
                    }

                    IsSignedIn = true;

                    callback.Invoke(AccountInfo, null);

                    OnSignedInEvent?.Invoke();
                });
            }, connection);
        }
예제 #26
0
 /// <summary>
 /// Set's lobby user properties (current player sets his own properties,
 ///  which can be accessed by game server and etc.)
 /// </summary>
 public void SetMyProperties(Dictionary <string, string> properties,
                             SuccessCallback callback, IClientSocket connection)
 {
     connection.SendMessage((short)MsfOpCodes.SetMyLobbyProperties, properties.ToBytes(),
                            Msf.Create.SuccessCallback(callback));
 }