added methods to send to all in lobby
This commit is contained in:
@@ -8,6 +8,15 @@ namespace SharedClientServer
|
||||
{
|
||||
class ClientServerUtil
|
||||
{
|
||||
// creates a message array to send to the server or to clients
|
||||
public byte[] createPayload(byte id, string payload)
|
||||
{
|
||||
byte[] stringAsBytes = Encoding.ASCII.GetBytes(payload);
|
||||
byte[] res = new byte[stringAsBytes.Length + 1];
|
||||
res[0] = id;
|
||||
Array.Copy(stringAsBytes, 0, res, 1, stringAsBytes.Length);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,12 @@ namespace SharedClientServer
|
||||
dynamic payload = JsonConvert.DeserializeObject(msg);
|
||||
return (payload.username, payload.message);
|
||||
}
|
||||
|
||||
public static string GetUsernameLogin(byte[] json)
|
||||
{
|
||||
string msg = Encoding.ASCII.GetString(json);
|
||||
dynamic payload = JsonConvert.DeserializeObject(msg);
|
||||
return payload.username;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,24 @@ namespace Client
|
||||
private int _id;
|
||||
private int _playersIn;
|
||||
private int _maxPlayers;
|
||||
private List<string> _usernames;
|
||||
|
||||
public void AddUsername(string username, out bool success)
|
||||
{
|
||||
success = false;
|
||||
if (_usernames.Count < _maxPlayers)
|
||||
{
|
||||
_usernames.Add(username);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Lobby(int id, int playersIn, int maxPlayers)
|
||||
{
|
||||
_id = id;
|
||||
_playersIn = playersIn;
|
||||
_maxPlayers = maxPlayers;
|
||||
_usernames = new List<string>();
|
||||
}
|
||||
|
||||
public int ID
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ClientServerUtil.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)JSONConvert.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Lobby.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user