-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #640 from misternebula/dev
0.30.2
- Loading branch information
Showing
20 changed files
with
232 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using OWML.Common; | ||
using QSB.Utility; | ||
|
||
namespace QSB.API; | ||
|
||
public static class AddonDataManager | ||
{ | ||
private static readonly Dictionary<string, Action<uint, object>> _handlers = new(); | ||
private static readonly Dictionary<int, Action<uint, object>> _handlers = new(); | ||
|
||
public static void OnReceiveDataMessage(string messageType, object data, uint from) | ||
public static void OnReceiveDataMessage(int hash, object data, uint from) | ||
{ | ||
DebugLog.DebugWrite($"Received data message of message type \"{messageType}\" from {from}!"); | ||
if (!_handlers.TryGetValue(messageType, out var handler)) | ||
DebugLog.DebugWrite($"Received addon message of with hash {hash} from {from}!"); | ||
if (!_handlers.TryGetValue(hash, out var handler)) | ||
{ | ||
DebugLog.DebugWrite($"unknown addon message type with hash {hash}", MessageType.Error); | ||
return; | ||
} | ||
|
||
handler(from, data); | ||
} | ||
|
||
public static void RegisterHandler<T>(string messageType, Action<uint, T> handler) | ||
public static void RegisterHandler<T>(int hash, Action<uint, T> handler) | ||
{ | ||
DebugLog.DebugWrite($"Registering handler for \"{messageType}\" with type of {typeof(T).Name}"); | ||
_handlers.Add(messageType, (from, data) => handler(from, (T)data)); | ||
DebugLog.DebugWrite($"Registering addon message handler for hash {hash} with type {typeof(T).Name}"); | ||
_handlers.Add(hash, (from, data) => handler(from, (T)data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using QSB.Messaging; | ||
using QSB.Player; | ||
using QSB.Utility; | ||
|
||
namespace QSB.API.Messages; | ||
|
||
public class AddonCustomDataSyncMessage : QSBMessage<(uint playerId, string key, byte[] data)> | ||
{ | ||
public AddonCustomDataSyncMessage(uint playerId, string key, object data) : base((playerId, key, data.ToBytes())) { } | ||
public override void OnReceiveRemote() => QSBPlayerManager.GetPlayer(Data.playerId).SetCustomData(Data.key, Data.data.ToObject()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.