Skip to content

Commit

Permalink
Mst 4.17.23b
Browse files Browse the repository at this point in the history
  • Loading branch information
aevien committed Jun 13, 2024
1 parent d79a643 commit efa75e2
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 855 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MasterServerToolkit.Logging;
using MasterServerToolkit.MasterServer;
using System;
using TMPro;
Expand Down Expand Up @@ -47,7 +48,8 @@ private void UpdateLocalization()
{
if (lableText != null)
{
lableText.text = Mst.Localization[localizationKey];
string text = Mst.Localization[localizationKey];
lableText.text = text;
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public struct MstOpCodes
public static ushort ConfirmEmail = nameof(ConfirmEmail).ToUint16Hash();
public static ushort GetLoggedInUsersCount = nameof(GetLoggedInUsersCount).ToUint16Hash();
public static ushort ChangePassword = nameof(ChangePassword).ToUint16Hash();
public static ushort GetPeerAccountInfo = nameof(GetPeerAccountInfo).ToUint16Hash();
public static ushort GetAccountInfoByPeer = nameof(GetAccountInfoByPeer).ToUint16Hash();
public static ushort GetAccountInfoByUsername = nameof(GetAccountInfoByUsername).ToUint16Hash();
public static ushort BindExtraProperties = nameof(BindExtraProperties).ToUint16Hash();

public static ushort PickUsername = nameof(PickUsername).ToUint16Hash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public override void Initialize(IServer server)
server.RegisterMessageHandler(MstOpCodes.GetEmailConfirmationCode, GetEmailConfirmationCodeMessageHandler);
server.RegisterMessageHandler(MstOpCodes.ConfirmEmail, ConfirmEmailMessageHandler);

server.RegisterMessageHandler(MstOpCodes.GetPeerAccountInfo, GetPeerAccountInfoMessageHandler);
server.RegisterMessageHandler(MstOpCodes.GetAccountInfoByPeer, GetAccountInfoByPeerMessageHandler);
server.RegisterMessageHandler(MstOpCodes.GetAccountInfoByUsername, GetAccountInfoByUsernameMessageHandler);

server.RegisterMessageHandler(MstOpCodes.BindExtraProperties, BindExtraPropertiesMessageHandler);
}
Expand Down Expand Up @@ -784,11 +785,43 @@ protected virtual async void GetEmailConfirmationCodeMessageHandler(IIncomingMes
message.Respond(ResponseStatus.Success);
}

private void GetAccountInfoByUsernameMessageHandler(IIncomingMessage message)
{
if (!HasGetPeerInfoPermissions(message.Peer))
{
message.Respond(ResponseStatus.Unauthorized);
return;
}

string username = message.AsString();
var userPeerExtension = GetLoggedInUserByUsername(username);

if (userPeerExtension == null)
{
logger.Error($"User with a given username {username} is not in the game");
message.Respond(ResponseStatus.NotFound);
return;
}

var userAccount = userPeerExtension.Account;

var userAccountPacket = new RoomUserAccountInfoPacket()
{
PeerId = userPeerExtension.Peer.Id,
ExtraProperties = userAccount.ExtraProperties,
Username = userAccount.Username,
UserId = userAccount.Id,
IsGuest = userAccount.IsGuest,
};

message.Respond(userAccountPacket, ResponseStatus.Success);
}

/// <summary>
/// Handles a request to retrieve account information
/// </summary>
/// <param name="message"></param>
protected virtual void GetPeerAccountInfoMessageHandler(IIncomingMessage message)
protected virtual void GetAccountInfoByPeerMessageHandler(IIncomingMessage message)
{
if (!HasGetPeerInfoPermissions(message.Peer))
{
Expand Down Expand Up @@ -817,7 +850,7 @@ protected virtual void GetPeerAccountInfoMessageHandler(IIncomingMessage message

var userAccount = userPeerExtension.Account;

var userAccountPacket = new PeerAccountInfoPacket()
var userAccountPacket = new RoomUserAccountInfoPacket()
{
PeerId = userPeerId,
ExtraProperties = userAccount.ExtraProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,79 @@ namespace MasterServerToolkit.MasterServer
{
public class MstAuthServer : MstBaseClient
{
public delegate void PeerAccountInfoCallback(PeerAccountInfoPacket accountInfo, string accountError);
public delegate void RoomUserAccountInfoCallback(RoomUserAccountInfoPacket accountInfo, string error);

public MstAuthServer(IClientSocket connection) : base(connection) { }

/// <summary>
///
/// </summary>
/// <param name="username"></param>
/// <param name="callback"></param>
public void GetAccountInfoByUsername(string username, RoomUserAccountInfoCallback callback)
{
GetAccountInfoByUsername(username, callback, Connection);
}

/// <summary>
///
/// </summary>
/// <param name="username"></param>
/// <param name="callback"></param>
/// <param name="connection"></param>
public void GetAccountInfoByUsername(string username, RoomUserAccountInfoCallback callback, IClientSocket connection)
{
if (!connection.IsConnected)
{
callback.Invoke(null, "Not connected to server");
return;
}

connection.SendMessage(MstOpCodes.GetAccountInfoByUsername, username, (status, response) =>
{
if (status != ResponseStatus.Success)
{
callback.Invoke(null, response.AsString("Unknown error"));
return;
}

var data = response.AsPacket<RoomUserAccountInfoPacket>();
callback.Invoke(data, null);
});
}

/// <summary>
/// Gets account information of a client, who is connected to master server,
/// and who's peer id matches the one provided
/// </summary>
/// <param name="peerId"></param>
/// <param name="callback"></param>
public void GetPeerAccountInfo(int peerId, PeerAccountInfoCallback callback)
public void GetAccountInfoByPeer(int peerId, RoomUserAccountInfoCallback callback)
{
GetPeerAccountInfo(peerId, callback, Connection);
GetAccountInfoByPeer(peerId, callback, Connection);
}

/// <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)
public void GetAccountInfoByPeer(int peerId, RoomUserAccountInfoCallback callback, IClientSocket connection)
{
if (!connection.IsConnected)
{
callback.Invoke(null, "Not connected to server");
return;
}

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

var data = response.AsPacket<PeerAccountInfoPacket>();
var data = response.AsPacket<RoomUserAccountInfoPacket>();

callback.Invoke(data, null);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MasterServerToolkit.MasterServer
{
public class PeerAccountInfoPacket : SerializablePacket
public class RoomUserAccountInfoPacket : SerializablePacket
{
public int PeerId { get; set; }
public string Username { get; set; }
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public MstProfilesServer(IClientSocket connection) : base(connection)
/// </summary>
public void FillProfileValues(ObservableServerProfile profile, SuccessCallback callback)
{
FillInProfileValues(profile, callback, Connection);
FillProfileValues(profile, callback, Connection);
}

/// <summary>
/// Sends a request to server, retrieves all profile values, and applies them to a provided
/// profile
/// </summary>
public void FillInProfileValues(ObservableServerProfile profile, SuccessCallback callback, IClientSocket connection)
public void FillProfileValues(ObservableServerProfile profile, SuccessCallback callback, IClientSocket connection)
{
if (!connection.IsConnected)
{
Expand Down
Loading

0 comments on commit efa75e2

Please sign in to comment.