MB 5 years ago
parent
commit
8a5e104ff0
5 changed files with 32 additions and 1 deletions
  1. +1
    -1
      Assets/Scenes/ClientScene.unity
  2. +5
    -0
      Assets/Scipts/Multiplayer/Client/ClientManager.cs
  3. +1
    -0
      Assets/Scipts/Multiplayer/Client/PlayersManager.cs
  4. +1
    -0
      Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs
  5. +24
    -0
      Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs

+ 1
- 1
Assets/Scenes/ClientScene.unity View File

@ -147,7 +147,7 @@ MonoBehaviour:
ConnectOnStart: 0
LobbyScene: LobbyScene
GameScene: TestScene
Name: The most nardish of players
Name: The Black Burrito
IsConnected: 0
ID: 0
--- !u!4 &914867462

+ 5
- 0
Assets/Scipts/Multiplayer/Client/ClientManager.cs View File

@ -88,6 +88,11 @@ namespace Multiplayer
Client.SendByChannel(msgType, msg, (int)channel);
}
public void SendMessage(short msgType)
{
SendMessage(msgType, new PlayerMsg(ID));
}
public void StartLobby(NetworkMessage msg)
{
UnityEngine.SceneManagement.SceneManager.LoadScene(LobbyScene);

+ 1
- 0
Assets/Scipts/Multiplayer/Client/PlayersManager.cs View File

@ -33,6 +33,7 @@ namespace Multiplayer
{
LocalPlayer = GameObject.Instantiate(LocalPlayerPrefab,transform);
LocalPlayer.transform.position = Vector3.zero;
ClientManager.Instance.SendMessage(PlayerMsgID.QueryPosition);
}
public void InstantiateRemotePlayer(byte playerID)

+ 1
- 0
Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs View File

@ -15,6 +15,7 @@ namespace Multiplayer
public const short GameWin = 203;
public const short GameOver = 204;
public const short GameStart = 205;
public const short QueryPosition = 206;
}
public class PlayerMsg : MessageBase

+ 24
- 0
Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs View File

@ -46,5 +46,29 @@ namespace Multiplayer
}
}
private void QueryPosition(NetworkMessage msg)
{
PlayerMsg playerMsg;
if (!Utility.ReadMessage<PlayerMsg>(msg, out playerMsg))
return;
if (!ServerManager.AllPlayers.ContainsKey(playerMsg.ID))
{
Debug.Log("Recieved query from unknown player");
return;
}
Player player = ServerManager.AllPlayers[playerMsg.ID];
foreach (Player otherPlayer in ServerManager.AllPlayers.Values)
{
if (otherPlayer.Equals(player))
continue;
VectorMsg vectorMsg = new VectorMsg(otherPlayer.ID, otherPlayer.Position);
player.Connection.Send(PlayerMsgID.Position, vectorMsg);
}
}
}
}

Loading…
Cancel
Save