RealTimeMovement Network


Overview

Developed as part of my coursework, this project extends a provided networking framework with custom implementations of client-server movement synchronization, input handling, and command send-receive systems on both the server and client sides. The focus was on building a responsive, modular architecture suitable for real-time multiplayer interaction.

View Repository


Client-Server Command Processing System Diagram

  • White border: process flow
  • Yellow border: network related classes

🖧 Server-Side Core Modules

1. GameLogic Class

Handles player session state on the server by exposing core utility methods that are invoked by NetworkServerProcessing. Rather than processing messages directly, it maintains a list of active players, assigns unique seeds to each new client, and supports data lookup for runtime updates such as connection, disconnection, and movement.

Provides server-side methods for registering, removing, and searching players.

public class GameLogic : MonoBehaviour
{
	public int m_PlayerSeed = 1000;
	public List<PlayerData> m_ConnectedPlayers = new List<PlayerData>();
 
	void Start() { NetworkServerProcessing.SetGameLogic(this); }
	
	public PlayerData Add(int clientConnectionID);
	public PlayerData Remove(int clientConnectionID);
	public PlayerData Search(int playerSeed);
}

  • Key Methods
    • PlayerData Add(int clientConnectionID):
      • Called when a new client connects. Assigns a unique seed and registers the player in the session list. Invoked by NetworkServerProcessing during initialization.
    • PlayerData Remove(int clientConnectionID):
      • Called on client disconnection. Finds and removes the player from the active session list. Used by NetworkServerProcessing to update the game state.
    • PlayerData Search(int playerSeed):
      • Returns a reference to a player based on their unique seed. Used by the server to apply updates like movement or input synchronization during gameplay.

2. NetworkServerProcessing Class

Acts as the core command dispatcher on the server side. This static class receives messages from connected clients, analyzes protocol signifiers, and dispatches appropriate logic. It coordinates with GameLogic to apply updates such as connection, disconnections, or movement events.

Provides centralized methods for analyzing, routing, and distributing protocol messages.

static public class NetworkServerProcessing
{
	static public void ReceivedMessageFromClient(string msg, int clientConnectionID, TransportPipeline pipeline);
	static public void SendMessageToClient(string msg, int clientConnectionID, TransportPipeline pipeline);
	
	static public void ConnectionEvent(int clientConnectionID);
	static public void DisconnectionEvent(int clientConnectionID);
}

  • Key Method
    static public void ReceivedMessageFromClient(string msg, int clientConnectionID, TransportPipeline pipeline)
    {
        string[] csv = msg.Split(',');
        int signifier = int.Parse(csv[0]);
        
        switch (signifier)
        {
    		case ClientToServerSignifiers.PTC_PLAYER_MOVE:
    		{
    		    string seed = csv[1];
    		    string posX = csv[2], posY = csv[3], posZ = csv[4];
    		
    		    // Update server-side position data
    		    gameLogic.Search(int.Parse(seed))?.SetData(posX, posY, posZ);
    		
    		    // Forward updated position to all connected clients
    		    string msgOut = $"{ServerToClientSignifiers.PTS_PLAYER_MOVE},{seed},{posX},{posY},{posZ}";
    		    foreach (PlayerData data in gameLogic.m_ConnectedPlayers)
    		        SendMessageToClient(msgOut, data.m_ClientConnectionID, TransportPipeline.ReliableAndInOrder);
    		}
    		break;
    		
    		case ClientToServerSignifiers.PTC_PLAYER_MOVE2:
    			// [Omitted] Input-based version of the above
    			break;
    	}
    }
    Handles incoming messages from clients, analyzes signifiers, and dispatches real-time server-side commands. Closely tied to GameLogic for applying session and movement updates.

🎮 Client-Side Core Modules

1. GameLogic Class

Handles player object state on the client by exposing core gameplay handlers invoked by NetworkClientProcessing. Rather than interpreting messages directly, it manages spawned players, updates positions, and removes them on disconnection in response to server instructions.

Provides client-side methods for spawning, updating, and removing players.

public class GameLogic : MonoBehaviour
{
	public Player m_prefabPlayer;
	public Player m_prefabOthers;
	public List<Player> m_ConnectedPlayers = new List<Player>();
 
	void Start() { NetworkClientProcessing.SetGameLogic(this); }
 
	public void SpawnMySelf(int mySeed, Vector3 position);
	public void SpawnOthers(int otherSeed, Vector3 position);
	public void MovePlayer(int movedPlayerSeed, Vector3 targetPos);
	public void MovePlayer(int movedPlayerSeed, Vector3 targetPos, Vector2 inputKeys);
	public void OtherPlayerLeft(int leftPlayerSeed);
}


2. NetworkClientProcessing Class

Acts as the core command handler on the client side. This static class receives messages from the server, analyzes protocol signifiers, and invokes appropriate game logic. It works alongside GameLogic to instantiate, update, or remove players based on server-driven state changes.

Provides centralized methods for analyzing, routing, and distributing protocol messages.

static public class NetworkClientProcessing
{
	static public void ReceivedMessageFromServer(string msg, TransportPipeline pipeline);
	static public void SendMessageToServer(string msg, TransportPipeline pipeline);
 
	static public void ConnectionEvent();
	static public void DisconnectionEvent();
}

  • Key Method
    static public void ReceivedMessageFromServer(string msg, TransportPipeline pipeline)
    {
    	string[] csv = msg.Split(',');
    	int signifier = int.Parse(csv[0]);
     
    	switch (signifier)
    	{
    		case ServerToClientSignifiers.PTS_CONNECTED_NEW_PLAYER:
    			// [Omitted] Initialize and spawn the local player
    			break;
    		case ServerToClientSignifiers.PTS_CONNECTED_NEW_PLAYER_RECEIVE_DATA:
    			// [Omitted] Receive and spawn existing players from server
    			break;
    		case ServerToClientSignifiers.PTS_CONNECTED_PLAYERS_RECEIVE_NEW_PLAYER_DATA:
    			// [Omitted] Spawn newly joined remote player on other clients
    			break;
    		case ServerToClientSignifiers.PTS_PLAYER_MOVE:
    			// [Omitted] Update remote player's position (Type A)
    			break;
    		case ServerToClientSignifiers.PTS_PLAYER_MOVE2:
    			// [Omitted] Update remote player's position & input (Type B)
    			break;
    		case ServerToClientSignifiers.PTS_PLAYER_LEFT:
    			// [Omitted] Remove disconnected player from scene
    			break;
    	}
    }
    Handles incoming messages from the server, analyzes signifiers, and applies client-side updates. Closely tied to GameLogic for spawning, movement, and player removal.

⚠️ Note: Logics are omitted. Full implementation available on the repository.


Conclusion

This project showcases a modular, protocol-driven approach to real-time multiplayer synchronization. With mirrored server-client logic and clear message handling, it provides a solid base for scalable and responsive player movement systems. This project reflects my understanding of client-server architecture and real-time game design fundamentals.