mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
stuff
This commit is contained in:
parent
56aac96738
commit
9e1212e918
@ -36,6 +36,12 @@ namespace QSB.Events
|
||||
() => _eventHandler.SendToServer(message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the message should be processed by the executing client/server.
|
||||
/// </summary>
|
||||
/// <returns>True if the message should be processed.</returns>
|
||||
public virtual bool CheckMessage(bool isServer, T message) => true;
|
||||
|
||||
private void OnReceive(bool isServer, T message)
|
||||
{
|
||||
/* Explanation :
|
||||
@ -45,6 +51,12 @@ namespace QSB.Events
|
||||
* onto all clients. This way, the server *server* just acts as the ditribution
|
||||
* hub for all events.
|
||||
*/
|
||||
|
||||
if (!CheckMessage(isServer, message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isServer)
|
||||
{
|
||||
_eventHandler.SendToAll(message);
|
||||
|
@ -1,5 +1,6 @@
|
||||
using OWML.Common;
|
||||
using QSB.Events;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
@ -22,6 +23,22 @@ namespace QSB.QuantumSync.Events
|
||||
AuthorityOwner = authorityOwner
|
||||
};
|
||||
|
||||
public override bool CheckMessage(bool isServer, QuantumAuthorityMessage message)
|
||||
{
|
||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
||||
var obj = objects.ToList()[message.ObjectId];
|
||||
|
||||
return obj.ControllingPlayer == 0 || message.AuthorityOwner == 0;
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(bool server, QuantumAuthorityMessage message)
|
||||
{
|
||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
||||
var obj = objects.ToList()[message.ObjectId];
|
||||
obj.ControllingPlayer = message.AuthorityOwner;
|
||||
DebugLog.DebugWrite($"Set {message.ObjectId} to owner {message.AuthorityOwner} - From local");
|
||||
}
|
||||
|
||||
public override void OnReceiveRemote(bool server, QuantumAuthorityMessage message)
|
||||
{
|
||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
||||
@ -32,6 +49,11 @@ namespace QSB.QuantumSync.Events
|
||||
}
|
||||
obj.ControllingPlayer = message.AuthorityOwner;
|
||||
DebugLog.DebugWrite($"Set {message.ObjectId} to owner {message.AuthorityOwner} - From {message.FromId}");
|
||||
if (obj.ControllingPlayer == 0 && obj.IsEnabled)
|
||||
{
|
||||
// object has no owner, but is still active for this player. request ownership
|
||||
GlobalMessenger<int, uint>.FireEvent(EventNames.QSBQuantumAuthority, message.ObjectId, QSBPlayerManager.LocalPlayerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
@ -3,5 +3,6 @@
|
||||
public interface IQSBQuantumObject
|
||||
{
|
||||
uint ControllingPlayer { get; set; }
|
||||
bool IsEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
where T : MonoBehaviour
|
||||
{
|
||||
public uint ControllingPlayer { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public override void Init(T attachedObject, int id)
|
||||
{
|
||||
@ -18,11 +19,12 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
tracker.AttachedComponent = AttachedObject.gameObject.GetComponent<T>();
|
||||
tracker.OnEnableEvent += OnEnable;
|
||||
tracker.OnDisableEvent += OnDisable;
|
||||
ControllingPlayer = QSBCore.IsServer ? 1u : 0u;
|
||||
ControllingPlayer = 0u;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
IsEnabled = true;
|
||||
if (ControllingPlayer != 0)
|
||||
{
|
||||
// controlled by another player, dont care that we activate it
|
||||
@ -31,11 +33,11 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
var id = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList().IndexOf(this);
|
||||
// no one is controlling this object right now, request authority
|
||||
GlobalMessenger<int, uint>.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId);
|
||||
ControllingPlayer = QSBPlayerManager.LocalPlayerId;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
IsEnabled = false;
|
||||
if (ControllingPlayer != QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
// not being controlled by us, don't care if we leave area
|
||||
@ -44,7 +46,6 @@ namespace QSB.QuantumSync.WorldObjects
|
||||
var id = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList().IndexOf(this);
|
||||
// send event to other players that we're releasing authority
|
||||
GlobalMessenger<int, uint>.FireEvent(EventNames.QSBQuantumAuthority, id, 0);
|
||||
ControllingPlayer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using QSB.Player;
|
||||
using QSB.QuantumSync.Events;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace QSB.QuantumSync.WorldObjects
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ namespace QSB.TransformSync
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (!QSBCore.HasWokenUp || !Player.IsReady)
|
||||
if (!QSBCore.HasWokenUp || !Player.IsReady || !QSBCore.DebugMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ namespace QSB.TransformSync
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (!QSBCore.HasWokenUp || !Player.IsReady)
|
||||
if (!QSBCore.HasWokenUp || !Player.IsReady || !QSBCore.DebugMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user