You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Multiplayer
{
public class PlayerServerManager
{
private ServerManager ServerManager;
public PlayerServerManager(ServerManager ServerManager)
{
this.ServerManager = ServerManager;
RegisterHandlers();
}
private void RegisterHandlers()
{
ServerManager.Server.RegisterHandler(PlayerMsgID.Position, RecievePosition);
}
private void RecievePosition(NetworkMessage msg)
{
VectorMsg vectorMsg;
if (!Utility.ReadMessage<VectorMsg>(msg, out vectorMsg))
return;
if (!ServerManager.AllPlayers.ContainsKey(vectorMsg.ID))
{
Debug.Log("Recieved position from unknown player");
return;
}
Player player = ServerManager.AllPlayers[vectorMsg.ID];
player.Position = vectorMsg.vector;
foreach(Player otherPlayer in ServerManager.AllPlayers.Values)
{
if (otherPlayer.Equals(player))
continue;
otherPlayer.Connection.Send(PlayerMsgID.Position, vectorMsg);
}
}
}
}