Ejemplo n.º 1
0
        /// <summary>
        /// Loads player profile
        /// </summary>
        /// <param name="successCallback"></param>
        public void LoadPlayerProfile(string username, SuccessCallback successCallback)
        {
            if (roomPlayersByUsername.ContainsKey(username))
            {
                RoomPlayer player = roomPlayersByUsername[username];

                Mst.Server.Profiles.FillProfileValues(player.Profile, (isSuccess, error) =>
                {
                    if (!isSuccess)
                    {
                        logger.Error("Room server cannot retrieve player profile from master server");
                        successCallback?.Invoke(false, "Room server cannot retrieve player profile from master server");

                        if (disconnectIfProfileFailed)
                        {
                            MstTimer.WaitForSeconds(1f, () => player.MirrorPeer.Disconnect());
                        }

                        return;
                    }

                    logger.Debug($"Profile of player {username} is successfully loaded. Player info: {player}");
                    successCallback?.Invoke(true, string.Empty);
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update profile info in database
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="callback"></param>
        public async void UpdateProfileAsync(ObservableServerProfile profile, SuccessCallback callback)
        {
            try
            {
                await Task.Run(() => UpdateProfile(profile));

                callback?.Invoke(true, string.Empty);
            }
            catch (Exception e)
            {
                callback?.Invoke(false, e.Message);
            }
        }
Ejemplo n.º 3
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (idTextBox.Text == null || idTextBox.Text == "")
     {
         MessageBox.Show("All Standalone Decks must have an ID");
         return;
     }
     if (drawmessagesDataGridView.Rows.Count > 1)
     {
         displayedDeck.drawmessages = new Dictionary <string, string>();
         foreach (DataGridViewRow row in drawmessagesDataGridView.Rows)
         {
             if (row.Cells[0].Value != null && row.Cells[1].Value != null)
             {
                 if (row.DefaultCellStyle == Utilities.DictionaryExtendStyle)
                 {
                     displayedDeck.drawmessages.Add(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString());
                 }
                 else if (row.DefaultCellStyle == Utilities.DictionaryRemoveStyle)
                 {
                     displayedDeck.drawmessages.Remove(row.Cells[0].Value.ToString());
                 }
                 else
                 {
                     displayedDeck.drawmessages.Add(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString());
                 }
             }
         }
     }
     Close();
     SuccessCallback?.Invoke(this, displayedDeck);
 }
Ejemplo n.º 4
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);
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Sets a ready status of current player
        /// </summary>
        public void SetReadyStatus(bool isReady, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

            connection.SendMessage((short)MsfOpCodes.LobbySetReady, isReady ? 1 : 0, (status, response) => {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Sets a default channel to the specified channel.
        ///     Messages, that have no channel, will be sent to default channel
        /// </summary>
        public void SetDefaultChannel(string channel, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

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

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Notifies master server that a user with a given peer id has left the room
        /// </summary>
        public void NotifyPlayerLeft(string roomId, int peerId, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, null);
                return;
            }

            var packet = new PlayerLeftRoomPacket()
            {
                PeerId = peerId,
                RoomId = roomId
            };

            connection.SendMessage((short)MsfOpCodes.PlayerLeftRoom, packet, (status, response) => {
                callback.Invoke(status == ResponseStatus.Success, null);
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Sends a request to server, to ask for a password reset
        /// </summary>
        public void RequestPasswordReset(string email, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected to server");
                return;
            }

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

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Destroys and unregisters the room
        /// </summary>
        public void Destroy(SuccessCallback callback)
        {
            Msf.Server.Rooms.DestroyRoom(RoomId, (isSuccess, error) => {
                if (!isSuccess)
                {
                    callback?.Invoke(false, error);
                    Logger.Error(error);
                    return;
                }

                Logger.Debug($"Room {RoomId} was successfully unregistered");

                callback?.Invoke(true, string.Empty);

                Connection = null;
                RoomId     = -1;
            }, Connection);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sends new options to master server
        /// </summary>
        public void SaveOptions(RoomOptions options, SuccessCallback callback, ErrorCallback errorCallback)
        {
            _roomsPlugin.SaveOptions(RoomId, options, () =>
            {
                Options = options;

                callback.Invoke();
            }, errorCallback.Invoke, Client);
        }
Ejemplo n.º 11
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (idTextBox.Text == null || idTextBox.Text == "")
            {
                MessageBox.Show("All Elements must have an ID");
                return;
            }
            if (aspectsDataGridView.Rows.Count > 1)
            {
                foreach (DataGridViewRow row in aspectsDataGridView.Rows)
                {
                    if (row.Cells[0].Value != null)
                    {
                        string key   = row.Cells[0].Value.ToString();
                        int?   value = row.Cells[1].Value != null?Convert.ToInt32(row.Cells[1].Value) : (int?)null;

                        if (row.DefaultCellStyle == Utilities.DictionaryExtendStyle)
                        {
                            if (displayedElement.aspects_extend == null)
                            {
                                displayedElement.aspects_extend = new Dictionary <string, int>();
                            }
                            if (!displayedElement.aspects_extend.ContainsKey(key))
                            {
                                displayedElement.aspects_extend.Add(key, value.Value);
                            }
                        }
                        else if (row.DefaultCellStyle == Utilities.DictionaryRemoveStyle)
                        {
                            if (displayedElement.aspects_remove == null)
                            {
                                displayedElement.aspects_remove = new List <string>();
                            }
                            if (!displayedElement.aspects_remove.Contains(key))
                            {
                                displayedElement.aspects_remove.Add(key);
                            }
                        }
                        else
                        {
                            if (displayedElement.aspects == null)
                            {
                                displayedElement.aspects = new Dictionary <string, int>();
                            }
                            if (!displayedElement.aspects.ContainsKey(key))
                            {
                                displayedElement.aspects.Add(key, value.Value);
                            }
                        }
                    }
                    //if (row.Cells[0].Value != null && row.Cells[1].Value != null) displayedElement.aspects.Add(row.Cells[0].Value.ToString(), Convert.ToInt32(row.Cells[1].Value));
                }
            }
            Close();
            SuccessCallback?.Invoke(this, displayedElement);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sends a request to leave a specified channel
        /// </summary>
        public void LeaveChannel(string channel, SuccessCallback callback)
        {
            if (!Connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

            Connection.SendMessage((short)OpCodes.LeaveChannel, channel, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 13
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (displayedEnding.id == null || displayedEnding.label == null || displayedEnding.image == null || displayedEnding.flavour == null || displayedEnding.description == null || displayedEnding.anim == null || displayedEnding.achievement == null)
     {
         MessageBox.Show("All values must be filled for the Ending to be valid.");
         return;
     }
     Close();
     SuccessCallback?.Invoke(this, displayedEnding);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Sends a request to set chat username
        /// </summary>
        public void PickUsername(string username, SuccessCallback callback, IClientSocket connection)
        {
            if (!connection.IsConnected)
            {
                callback.Invoke(false, "Not connected");
                return;
            }

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

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 15
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (idTextBox.Text == null || idTextBox.Text == "")
     {
         MessageBox.Show("All Verbs must have an ID");
         return;
     }
     Close();
     SuccessCallback?.Invoke(this, displayedVerb);
 }
Ejemplo n.º 16
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (idTextBox.Text == null || idTextBox.Text == "")
     {
         MessageBox.Show("All Aspects must have an ID.");
         return;
     }
     if (inducesDataGridView.Rows.Count > 1)
     {
         displayedAspect.induces         = null;
         displayedAspect.induces_append  = null;
         displayedAspect.induces_prepend = null;
         displayedAspect.induces_remove  = null;
         foreach (DataGridViewRow row in inducesDataGridView.Rows)
         {
             if (row.Cells[0].Value != null && row.Cells[1].Value != null)
             {
                 if (row.DefaultCellStyle.BackColor == Utilities.ListAppendColor)
                 {
                     if (displayedAspect.induces_append == null)
                     {
                         displayedAspect.induces_append = new List <Induces>();
                     }
                     displayedAspect.induces_append.Add(new Induces(row.Cells[0].Value as string, Convert.ToInt32(row.Cells[1].Value), Convert.ToBoolean(row.Cells[2].Value), null));
                 }
                 else if (row.DefaultCellStyle.BackColor == Utilities.ListPrependColor)
                 {
                     if (displayedAspect.induces_prepend == null)
                     {
                         displayedAspect.induces_prepend = new List <Induces>();
                     }
                     displayedAspect.induces_prepend.Add(new Induces(row.Cells[0].Value as string, Convert.ToInt32(row.Cells[1].Value), Convert.ToBoolean(row.Cells[2].Value), null));
                 }
                 else if (row.DefaultCellStyle.BackColor == Utilities.ListRemoveColor)
                 {
                     if (displayedAspect.induces_remove == null)
                     {
                         displayedAspect.induces_remove = new List <String>();
                     }
                     displayedAspect.induces_remove.Add(row.Cells[0].Value as string);
                 }
                 else
                 {
                     if (displayedAspect.induces == null)
                     {
                         displayedAspect.induces = new List <Induces>();
                     }
                     displayedAspect.induces.Add(new Induces(row.Cells[0].Value as string, Convert.ToInt32(row.Cells[1].Value), Convert.ToBoolean(row.Cells[2].Value), null));
                 }
             }
         }
     }
     Close();
     SuccessCallback?.Invoke(this, displayedAspect);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Current player sends a request to join a team
        /// </summary>
        public void JoinTeam(int lobbyId, string teamName, SuccessCallback callback)
        {
            var packet = new LobbyJoinTeamPacket()
            {
                LobbyId  = lobbyId,
                TeamName = teamName
            };

            Connection.SendMessage((short)OpCodes.JoinLobbyTeam, packet,
                                   (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    callback.Invoke(false, response.AsString("unknown error"));
                    return;
                }

                callback.Invoke(true, null);
            });
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Send's new options to master server
        /// </summary>
        public void SaveOptions(RoomOptions options, SuccessCallback callback)
        {
            Msf.Server.Rooms.SaveOptions(RoomId, options, (successful, error) => {
                if (successful)
                {
                    Options = options;
                }

                callback.Invoke(successful, error);
            }, Connection);
        }
Ejemplo n.º 19
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();
            });
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Sends a request to start a game
        /// </summary>
        public void StartGame(SuccessCallback callback, ErrorCallback errorCallback)
        {
            Client.SendMessage((ushort)OpCodes.LobbyStartGame, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke();
            });
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Sends a generic message packet to server
        /// </summary>
        public void SendMessage(ChatMessagePacket packet, SuccessCallback callback, ErrorCallback errorCallback)
        {
            Client.SendMessage((ushort)OpCodes.ChatMessage, packet, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown error"));
                    return;
                }

                callback.Invoke();
            });
        }
Ejemplo n.º 22
0
 /// <summary>
 /// execute commplete
 /// </summary>
 /// <param name="success">success</param>
 public async Task ExecuteCompleteAsync(bool success)
 {
     await Task.Run(() =>
     {
         if (success)
         {
             SuccessCallback?.Invoke(CallbackRequest);
         }
         else
         {
             FailedCallback?.Invoke(CallbackRequest);
         }
     }).ConfigureAwait(false);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// execute commplete
 /// </summary>
 /// <param name="success">success</param>
 public void ExecuteComplete(bool success)
 {
     Task.Run(() =>
     {
         if (success)
         {
             SuccessCallback?.Invoke(CallbackRequest);
         }
         else
         {
             FailedCallback?.Invoke(CallbackRequest);
         }
     });
 }
Ejemplo n.º 24
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);
            });
        }
Ejemplo n.º 25
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);
            });
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Sets 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, ErrorCallback errorCallback)
        {
            Client.SendMessage((ushort)OpCodes.SetMyLobbyProperties, properties.ToBytes(),
                               (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("unknown error"));
                    return;
                }

                callback.Invoke();
            });
        }
Ejemplo n.º 27
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);
            });
        }
Ejemplo n.º 28
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);
            });
        }
Ejemplo n.º 29
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);
            });
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Sends a registration request to given connection
        /// </summary>
        public void Register(Dictionary <string, string> data, SuccessCallback callback, ErrorCallback errorCallback)
        {
            if (!Client.IsConnected)
            {
                errorCallback.Invoke("Not connected to server");
                return;
            }

            if (_isLoggingIn)
            {
                errorCallback.Invoke("Log in is already in progress");
                return;
            }

            if (IsLoggedIn)
            {
                errorCallback.Invoke("Already logged in");
                return;
            }

            // We first need to get an aes key
            // so that we can encrypt our login data
            _securityPlugin.GetAesKey(aesKey =>
            {
                if (aesKey == null)
                {
                    errorCallback.Invoke("Failed to register due to security issues");
                    return;
                }

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

                Client.SendMessage((ushort)OpCodes.RegisterAccount, encryptedData, (status, response) =>
                {
                    if (status != ResponseStatus.Success)
                    {
                        errorCallback.Invoke(response.AsString("Unknown error"));
                        return;
                    }

                    callback.Invoke();
                });
            });
        }