using Cyber.Entities.SyncBases;
using Cyber.Networking.Messages;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Cyber.Networking.Serverside {
///
/// The Server sync handler handles sync packets coming from the client, see .
///
public class ServerSyncHandler {
private Dictionary LastSyncIDReceived = new Dictionary();
private Dictionary Players;
///
/// Creates a nwe Server Sync handler for handling sync packets that are coming from the client.
///
///
public ServerSyncHandler(Dictionary players) {
Players = players;
}
///
/// Handle the given sync from a client. Must be checked to be first.
///
///
public void HandleSyncPkt(NetworkMessage message) {
ClientSyncPkt SyncPkt = new ClientSyncPkt();
SyncPkt.Deserialize(message.reader);
int LastID = -1;
if (LastSyncIDReceived.ContainsKey(message.conn.connectionId)) {
LastID = LastSyncIDReceived[message.conn.connectionId];
}
if (SyncPkt.ClientSyncID > LastID) {
SyncPkt.ReadTheRest(message.reader);
LastSyncIDReceived[message.conn.connectionId] = SyncPkt.ClientSyncID;
Character PlayerCharacter = Players[message.conn.connectionId].Character;
PlayerCharacter.Move(SyncPkt.MoveDirection);
PlayerCharacter.SetRotation(SyncPkt.Rotation);
Debug.Log("MoveDirection: " + SyncPkt.MoveDirection);
}
// Disregard the package, it's too old.
}
}
}