mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-28 22:23:05 +00:00
Also sync game packets
This commit is contained in:
parent
e917010e08
commit
09ff142a39
2 changed files with 13 additions and 3 deletions
|
@ -9,7 +9,7 @@ using Shared.Packet.Packets;
|
||||||
namespace Server;
|
namespace Server;
|
||||||
|
|
||||||
public class Client : IDisposable {
|
public class Client : IDisposable {
|
||||||
public readonly ConcurrentDictionary<string, object> Metadata = new ConcurrentDictionary<string, object>(); // can be used to store any information about a player
|
public readonly ConcurrentDictionary<string, object?> Metadata = new ConcurrentDictionary<string, object?>(); // can be used to store any information about a player
|
||||||
public bool Connected = false;
|
public bool Connected = false;
|
||||||
public CostumePacket? CurrentCostume = null; // required for proper client sync
|
public CostumePacket? CurrentCostume = null; // required for proper client sync
|
||||||
public string Name {
|
public string Name {
|
||||||
|
|
|
@ -17,9 +17,18 @@ server.ClientJoined += (c, _) => {
|
||||||
c.Metadata["loadedSave"] = false;
|
c.Metadata["loadedSave"] = false;
|
||||||
c.Metadata["scenario"] = 0;
|
c.Metadata["scenario"] = 0;
|
||||||
c.Metadata["2d"] = false;
|
c.Metadata["2d"] = false;
|
||||||
|
foreach (Client client in server.Clients.Where(client => client.Metadata["lastGamePacket"] != null).ToArray()) {
|
||||||
|
try {
|
||||||
|
await c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// lol who gives a fuck
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.PacketTransformer += (sender, packet) => {
|
c.PacketTransformer += (sender, packet) => {
|
||||||
if (Settings.Instance.Scenario.MergeEnabled && packet is GamePacket gamePacket) {
|
if (Settings.Instance.Scenario.MergeEnabled && packet is GamePacket gamePacket) {
|
||||||
gamePacket.ScenarioNum = (byte) c.Metadata["scenario"];
|
gamePacket.ScenarioNum = (byte?) c.Metadata["scenario"] ?? 0;
|
||||||
return gamePacket;
|
return gamePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +38,7 @@ server.ClientJoined += (c, _) => {
|
||||||
|
|
||||||
async Task ClientSyncShineBag(Client client) {
|
async Task ClientSyncShineBag(Client client) {
|
||||||
try {
|
try {
|
||||||
ConcurrentBag<int> clientBag = ((ConcurrentBag<int>)client.Metadata["shineSync"]);
|
ConcurrentBag<int> clientBag = (ConcurrentBag<int>) (client.Metadata["shineSync"] ??= new ConcurrentBag<int>());
|
||||||
foreach (int shine in shineBag.Except(clientBag).ToArray()) {
|
foreach (int shine in shineBag.Except(clientBag).ToArray()) {
|
||||||
clientBag.Add(shine);
|
clientBag.Add(shine);
|
||||||
await client.Send(new ShinePacket {
|
await client.Send(new ShinePacket {
|
||||||
|
@ -67,6 +76,7 @@ server.PacketHandler = (c, p) => {
|
||||||
case GamePacket gamePacket: {
|
case GamePacket gamePacket: {
|
||||||
c.Metadata["scenario"] = gamePacket.ScenarioNum;
|
c.Metadata["scenario"] = gamePacket.ScenarioNum;
|
||||||
c.Metadata["2d"] = gamePacket.Is2d;
|
c.Metadata["2d"] = gamePacket.Is2d;
|
||||||
|
c.Metadata["lastGamePacket"] = gamePacket;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TagPacket tagPacket: {
|
case TagPacket tagPacket: {
|
||||||
|
|
Loading…
Reference in a new issue