Hi I’ve looked through the entire forum, if I’ve missed it I appologise, however I couldn’t find what I was looking for.
I have a problem with a project I am working on, specifically I am creating an online multiplayer framework, which uses a half-authoritive client-server model, I have everything setup for all the data handling and message processing. Except I cannot seem to figure out how to get my RPC messages to send from server to client, or vice’a’versa. I originally had two scenes, one for the server, one for the game world. An object with a script called ConnectionProcessor, which managed incoming connections, and disconnections, it also starts up the basic RPC messaging pipe I’m trying to create. This “messaging pipe” is simply one script, which on the server side relays incoming rpcs to the local “MessageProcessor” script. And on the client side relays incoming rpcs to the local “MessageProcessor” script there. The two MessageProcessor scripts, ServerMsg, and ClientMsg both have a simple interface for the ConnectionProcessor script to connect to without having complicated code to determine where the messages are relayed. A function in the message handling scripts called “Msg(message : String)” handles incoming messages that are relayed to the script. However I cannot seem to get this function to recieve any relayed RPC messages. I’ve tested the message handling scripts work, they do fine. I’ve tested that the server is sending initial RPC messages, it is, but the client isn’t recieving them. On both the client and the server the ConnectionProcessor object has a network view with identical IDs. To try and solve my problem I thought maybe it was because it was in separate scenes, so I moved it all into one scene, disabling and enabling components and objects for each separate build (server client). I can’t use one set of scripts for both server client, the closest I can is the connection handling script, simply because the client will be processing a heap load of data optimization and processing functions. And the server has to run as fast as possible. I’ve tried adding dummy scenes to push the servers copy of the world scene up to the same level index, scene loads fine still, but still no luck. The client can connect to the server, and the server is detecting the connection, and sending an InitUser RPC function, but the client isn’t recieving it. I’ve tried putting the network views into the same group by script, no luck. I just don’t get what I’m doing wrong, and this is starting to do my head, as reading this is probably doing yours right? Any help would be appreciated, some code for you to examine below, all js:
ConnectionProcessor.js
private var localPlayer : NetworkPlayer;
private var localTransformViewID : NetworkViewID;
private var localAnimationViewID : NetworkViewID;
private var playerInfo : Array = new Array();
private var _serverMessageProcessor : ServerMsg;
private var _clientMessageProcessor : ClientMsg;
function Awake () {
networkView.group = 1;
}
function IsServer () {
_serverMessageProcessor = GameObject.FindWithTag("MessageProcessor").GetComponent("ServerMsg");
}
function IsClient () {
_clientMessageProcessor = GameObject.FindWithTag("MessageProcessor").GetComponent("ClientMsg");
}
class PlayerInfo {
var transformViewID : NetworkViewID;
var animationViewID : NetworkViewID;
var player : NetworkPlayer;
}
@RPC
function InitUser (player : NetworkPlayer, tViewID : NetworkViewID, aViewID : NetworkViewID) {
_serverMessageProcessor.Msg("RPC RECIEVED: InitUser");
Debug.Log("Recieved player init " + player + ". ViewIDs " + tViewID + " and " + aViewID);
localPlayer = player;
localTransformViewID = tViewID;
localAnimationViewID = aViewID;
}
@RPC
function Recv (message : String) {
if (Network.isServer) {
_serverMessageProcessor.Msg(message);
}
else if (Network.isClient) {
_clientMessageProcessor.Msg(message);
}
}
public function Send (message : String, destination : RPCMode) {
if (Network.isClient) {
networkView.RPC("Recv", RPCMode.Server, message);
}
else if (Network.isServer) {
networkView.RPC("Recv", RPCMode.Others, message);
}
}
function OnPlayerConnected (player : NetworkPlayer) {
Debug.Log("Sending player init to " + player);
var transformViewID : NetworkViewID = Network.AllocateViewID();
var animationViewID : NetworkViewID = Network.AllocateViewID();
Debug.Log("Player given view IDs " + transformViewID + " and " + animationViewID);
_serverMessageProcessor.Msg("RPC SENT: InitUser");
networkView.RPC("InitUser", player, player, transformViewID, animationViewID);
}
function OnPlayerDisconnected (player : NetworkPlayer) {
Debug.Log("Cleaning up player " + player);
var deletePlayer : PlayerInfo;
for (var playerInstance : PlayerInfo in playerInfo) {
if (player == playerInstance.player) {
Debug.Log("Destroying objects belonging to view ID " + playerInstance.transformViewID);
Network.Destroy(playerInstance.transformViewID);
deletePlayer = playerInstance;
}
}
playerInfo.Remove(deletePlayer);
Network.RemoveRPCs(player, 0);
Network.DestroyPlayerObjects(player);
}
function OnConnectedToServer() {
GameObject.FindWithTag("AccountManagement").GetComponent("Login").BeginLogin();
}
function OnDisconnectedFromServer () {
Application.LoadLevel(0);
}
ServerMsg.js
private var _connectionProcessor : ConnectionProcessor;
private var _msgHistory : Array = new Array();
private var _scrollpos : Vector2 = Vector2.zero;
function Start () {
_connectionProcessor = GameObject.FindWithTag("ConnectionProcessor").GetComponent("ConnectionProcessor");
Msg("Server-Client RPC Messaging System Active");
}
public function Msg (message : String) {
_msgHistory.Add(message);
}
public function Send (message : String, destination : RPCMode) {
_connectionProcessor.Send(message, destination);
}
function OnGUI () {
_scrollpos = GUI.BeginScrollView(Rect(0,0,Screen.width,Screen.height),_scrollpos,Rect(8,8,Screen.width-32,Screen.height-16));
var n : int = 0;
for (var msg : String in _msgHistory)
{
GUI.Label(Rect(8,8+(n*20),Screen.width-16,20),msg);
n++;
}
GUI.EndScrollView();
}
ClientMsg.js
private var _connectionProcessor : ConnectionProcessor;
private var _msgHistory : Array = new Array();
private var _scrollpos : Vector2 = Vector2.zero;
function Awake () {
_connectionProcessor = GameObject.FindWithTag("ConnectionProcessor").GetComponent("ConnectionProcessor");
Msg("Client-Server RPC Messaging System Active");
}
public function Msg (message : String) {
_msgHistory.Add(message);
}
public function Send (message : String, destination : RPCMode) {
_connectionProcessor.Send(message, destination);
}
function OnGUI () {
_scrollpos = GUI.BeginScrollView(Rect(0,0,Screen.width,Screen.height),_scrollpos,Rect(8,8,Screen.width-32,(Screen.height/2)-48));
var n : int = 0;
for (var msg : String in _msgHistory)
{
GUI.Label(Rect(8,8+(n*20),Screen.width-16,20),msg);
n++;
}
GUI.EndScrollView();
}
Please help, thanks in advance,
Jamie.