mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
Separate handler for client and server
This commit is contained in:
parent
22b6692642
commit
d6e1f4c2a4
@ -6,10 +6,11 @@ namespace QSB {
|
||||
protected abstract short type { get; }
|
||||
|
||||
public MessageHandler () {
|
||||
NetworkServer.RegisterHandler(SectorMessage.Type, OnReceiveMessage);
|
||||
NetworkManager.singleton.client.RegisterHandler(SectorMessage.Type, OnReceiveMessage);
|
||||
NetworkServer.RegisterHandler(SectorMessage.Type, OnServerReceiveMessage);
|
||||
NetworkManager.singleton.client.RegisterHandler(SectorMessage.Type, OnClientReceiveMessage);
|
||||
}
|
||||
|
||||
protected abstract void OnReceiveMessage (NetworkMessage netMsg);
|
||||
protected abstract void OnClientReceiveMessage (NetworkMessage netMsg);
|
||||
protected abstract void OnServerReceiveMessage (NetworkMessage netMsg);
|
||||
}
|
||||
}
|
||||
|
10
QSB/QSB.cs
10
QSB/QSB.cs
@ -26,8 +26,6 @@ namespace QSB {
|
||||
|
||||
gameObject.AddComponent<QSBNetworkManager>();
|
||||
gameObject.AddComponent<NetworkManagerHUD>();
|
||||
|
||||
ModHelper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "OnAddSector");
|
||||
}
|
||||
|
||||
static string JoinAll (params object[] logObjects) {
|
||||
@ -51,13 +49,5 @@ namespace QSB {
|
||||
NotificationData data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true);
|
||||
NotificationManager.SharedInstance.PostNotification(data, false);
|
||||
}
|
||||
|
||||
static class Patches {
|
||||
static void OnAddSector (Sector sector, PlayerSectorDetector __instance) {
|
||||
if (NetworkPlayer.localInstance != null) {
|
||||
NetworkPlayer.localInstance.EnterSector(sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ namespace QSB {
|
||||
void Awake () {
|
||||
playerSectors = new Dictionary<uint, Transform>();
|
||||
_allSectors = FindObjectsOfType<Sector>();
|
||||
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "PreAddSector");
|
||||
}
|
||||
|
||||
public static void SetSector (NetworkInstanceId netId, Sector.Name sectorName) {
|
||||
@ -30,7 +32,7 @@ namespace QSB {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnReceiveMessage (NetworkMessage netMsg) {
|
||||
protected override void OnClientReceiveMessage (NetworkMessage netMsg) {
|
||||
SectorMessage msg = netMsg.ReadMessage<SectorMessage>();
|
||||
|
||||
var sectorName = (Sector.Name) msg.sectorId;
|
||||
@ -44,5 +46,18 @@ namespace QSB {
|
||||
QSB.LogToScreen("Found sector", sectorName, ", setting for", msg.senderId);
|
||||
playerSectors[msg.senderId] = sectorTransform;
|
||||
}
|
||||
|
||||
protected override void OnServerReceiveMessage (NetworkMessage netMsg) {
|
||||
SectorMessage msg = netMsg.ReadMessage<SectorMessage>();
|
||||
NetworkServer.SendToAll(MessageType.Sector, msg);
|
||||
}
|
||||
|
||||
static class Patches {
|
||||
static void PreAddSector (Sector sector, PlayerSectorDetector __instance) {
|
||||
if (NetworkPlayer.localInstance != null) {
|
||||
NetworkPlayer.localInstance.EnterSector(sector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user