Skip to content

Add Minigame Provisioning #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Uchu.World/Enums/MatchRequestType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Uchu.World
{
public enum MatchRequestType
{
Join = 0,
SetReady = 1,
}
}
12 changes: 12 additions & 0 deletions Uchu.World/Enums/MatchUpdateType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Uchu.World
{
public enum MatchUpdateType
{
PlayerAdded = 0,
PlayerRemoved = 1,
SetInitialTime = 3,
SetTime = 4,
PlayerReady = 5,
PlayerNotReady = 6,
}
}
29 changes: 24 additions & 5 deletions Uchu.World/Handlers/GameMessages/MatchHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Uchu.Core;
using Uchu.World.Systems.Match;

namespace Uchu.World.Handlers.GameMessages
{
Expand All @@ -8,10 +8,29 @@ public class MatchHandler : HandlerGroup
[PacketHandler]
public void MatchRequestHandler(MatchRequestMessage message, Player player)
{
player.SendChatMessage(
$"Match Request:\nType: {message.Type}\nValue: {message.Value}\n{message.Activator}\n{message.Settings}",
PlayerChatChannel.Normal
);
if (message.Type == MatchRequestType.Join)
{
// Add the player to a match or remove them.
if (message.Value == 0)
{
Provisioner.PlayerLeft(player);
}
else
{
Provisioner.GetProvisioner(message.Value).AddPlayer(player);
}
}
else if (message.Type == MatchRequestType.SetReady)
{
// Set the player as ready or not.
if (message.Value == 1)
{
Provisioner.PlayerReady(player);
} else if (message.Value == 0)
{
Provisioner.PlayerNotReady(player);
}
}
}
}
}
10 changes: 5 additions & 5 deletions Uchu.World/Packets/GameMessages/Client/MatchRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MatchRequestMessage : ClientGameMessage
{
public override GameMessageId GameMessageId => GameMessageId.MatchRequest;

public int Type { get; set; }
public MatchRequestType Type { get; set; }

public int Value { get; set; }

Expand All @@ -18,15 +18,15 @@ public class MatchRequestMessage : ClientGameMessage

public override void Deserialize(BitReader reader)
{
Type = reader.Read<int>();

Value = reader.Read<int>();

Activator = reader.ReadGameObject(Associate.Zone);

var ldl = reader.ReadString((int) reader.Read<uint>(), true);

Settings = LegoDataDictionary.FromString(ldl);

Type = (MatchRequestType) reader.Read<int>();

Value = reader.Read<int>();
}
}
}
16 changes: 16 additions & 0 deletions Uchu.World/Packets/GameMessages/Server/MatchResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using RakDotNet.IO;

namespace Uchu.World
{
public class MatchResponse : ServerGameMessage
{
public override GameMessageId GameMessageId => GameMessageId.MatchResponse;

public int Response { get; set; } // TODO: Can/should this be an enum?

public override void SerializeMessage(BitWriter writer)
{
writer.Write(Response);
}
}
}
28 changes: 28 additions & 0 deletions Uchu.World/Packets/GameMessages/Server/MatchUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using RakDotNet.IO;
using Uchu.Core;

namespace Uchu.World
{
public class MatchUpdate : ServerGameMessage
{
public override GameMessageId GameMessageId => GameMessageId.MatchUpdate;

public string Data { get; set; }

public MatchUpdateType Type { get; set; }

public override void SerializeMessage(BitWriter writer)
{
writer.Write((uint) Data.Length);

if (Data.Length > 0)
{
writer.WriteString(Data, Data.Length, true);
writer.Write((byte) 0);
writer.Write((byte) 0);
}

writer.Write((int) Type);
}
}
}
Loading