public void ResponseProcessor(ResponseOperationMessage rmsg) { switch (rmsg.MsgType) { case MessageType.CreateRoom: var crParams = rmsg.CrrParams; switch (crParams.ReturnValue) { case (uint)ResponseMessageInfo.CreateRoomSuccess: LocalPlayer = new NGPlayer(true, crParams.PeerId); NGEvent.OnCreatedRoom(); break; case (uint)ResponseMessageInfo.CreateRoomAlreadyExist: NGEvent.OnCreateRoomFailed(crParams.Message); break; } break; case MessageType.JoinRoom: var jrrParams = rmsg.JrrParams; switch (jrrParams.ReturnValue) { case (uint)ResponseMessageInfo.JoinRoomSuccess: NGLogger.LogDebug("JoinRoomSuccess responsee"); LocalPlayer = new NGPlayer(true, jrrParams.PeerId); NGEvent.OnJoinedRoom(); break; case (uint)ResponseMessageInfo.JoinRoomAlreadyInRoom: NGEvent.OnJoinRoomFailed(); break; case (uint)ResponseMessageInfo.JoinRoomFull: NGEvent.OnJoinRoomFailed(); break; default: NGLogger.LogError("The return value from JoinRoom or JoinOrCreateRoom" + jrrParams.ReturnValue + " cannot be identified."); break; } break; case MessageType.LeaveRoom: var lrParams = rmsg.LrrParams; switch (lrParams.ReturnValue) { case (uint)ResponseMessageInfo.LeaveRoomSuccess: NGEvent.OnLeftRoom(); break; } break; } }
public NGPlayer GetNGPlayer(uint peerid) { NGPlayer rv = null; if (!ID2OtherPlayers.TryGetValue(peerid, out rv)) { NGLogger.LogWarning("NGPlayer with ID" + peerid.ToString() + " cannot be found."); } return(rv); }
private void ProcessRecieveData(byte[] data) { //NGLogger.LogInfo("Receive a message"); Stream stream = new MemoryStream(data); ReceiveMessage message = ReadMessage <ReceiveMessage>(stream); switch (message.ReceiveMsgType) { case ReceiveMessageType.ResponseSocketStatus: switch (message.RssMsg.SStatus) { case SocketStatus.Connected: NGNetwork.Status = SocketStatus.Connected; NGNetworkEvent.OnConnected(); break; } break; case ReceiveMessageType.ResponseOperation: ResponseOperationMessage rmsg = message.RoMsg; NGInterface.CurrentRoom().ResponseProcessor(rmsg); break; case ReceiveMessageType.Forward: ForwardMessage fmsg = message.FMsg; uint peerId = fmsg.PeerId; switch (fmsg.MsgType) { case MessageType.JoinRoom: var jrParams = fmsg.JrfParams; NGPlayer newplayer = new NGPlayer(false, peerId); NGInterface.CurrentRoom().AddPlayer(newplayer); NGEvent.OnOtherPlayerEnteredRoom(newplayer); break; case MessageType.JoinOrCreateRoom: var jocParams = fmsg.JocrfParams; NGPlayer player = new NGPlayer(false, peerId); NGInterface.CurrentRoom().AddPlayer(player); NGEvent.OnOtherPlayerEnteredRoom(player); break; case MessageType.LeaveRoom: var lParams = fmsg.LrfParams; NGLogger.LogDebug("LeaveRoom" + peerId); var leaveplayer = NGInterface.CurrentRoom().GetNGPlayer(peerId); NGEvent.OnOtherPlayerLeftRoom(leaveplayer); Destroy(leaveplayer.GO); NGInterface.CurrentRoom().RemovePlayer(peerId); break; case MessageType.Rpc: var rpcparams = fmsg.RfParams; NGAny[] objs = NGProtobufConverter <NGAny> .RepeatedField2Array(rpcparams.Parameters); NGRPC.ExcuteRPC(rpcparams.ViewID, rpcparams.MethodName, objs); break; case MessageType.Instantiation: var i = fmsg.IfParams; var ids = NGProtobufConverter <uint> .RepeatedField2Array(i.ViewIDs); NGInterface.CurrentRoom().Instantiate(peerId, false, ids, i.PrefabName, i.Position, i.Rotation); break; case MessageType.ViewSync: var viewsyncparams = fmsg.VsfParams; var viewParams = viewsyncparams.VsdParams; NGViewContainer container = new NGViewContainer(); container.DeserializeAll(viewParams); break; case MessageType.CustomEvent: var ceParams = fmsg.CeParams; NGEvent.OnCustomEvent(ceParams.EventID, NGProtobufConverter <NGAny> .RepeatedField2Array(ceParams.CustomData)); break; } break; } }
public virtual void OnOtherPlayerLeftRoom(NGPlayer player) { }
public virtual void OnOtherPlayerEnteredRoom(NGPlayer player) { }
public void AddPlayer(NGPlayer player) { ID2OtherPlayers.Add(player.mPeerId, player); }