private void ConnectInfoResponse(byte[] bytes, IPEndPoint refEp) { //send ack ConnectInfo conv = ConversationFactory.Instance .CreateFromMessage <ConnectInfo>(bytes, refEp, null, null, null); conv.Start(); //connect to server ConnectMsg msg = Message.Decode <ConnectMsg>(bytes); gameServer = msg.GameServer; //open tcp connection TCPClient tcp = new TCPClient(); tcp.SetupConnection(); int gamePort = tcp.port; tcpClients.Add(tcp); //send message with info on which port ConnectGameServer connectConv = ConversationFactory.Instance .CreateFromConversationType <ConnectGameServer> (gameServer, null, null, null); connectConv._GameId = 1; connectConv._NumPlayers = 1; connectConv._Port = gamePort; connectConv.Start(); }
public void SentinelServiceMsgs_ConnectMsg_Clone() { ConnectMsg msgIn, msgOut; msgOut = new ConnectMsg(); msgIn = (ConnectMsg)msgOut.Clone(); Assert.IsNotNull(msgIn); TestBaseCloning(msgOut); }
public void SentinelServiceMsgs_ConnectMsg_Serialize() { ConnectMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); msgOut = new ConnectMsg(); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (ConnectMsg)Msg.Load(es); Assert.IsNotNull(msgIn); }
public override Message CreateFirstMessage() { ConnectMsg msg = new ConnectMsg() { ConvId = ConvId, MsgId = MessageId.Create(), MessageType = TypeOfMessage.ConnectInfoMsg, GameServer = _gameServer }; return(msg); }
public override void ResponderConversation(ref object context) { incomingMsg = MyQueue.Dequeue(Timeout); if (incomingMsg == null) { return; } Send(CreateAck()); ConnectMsg msg = Message.Decode <ConnectMsg>(incomingMsg); context = msg.GameServer; }
void IObserver <Message> .OnNext(Message msg) { switch (msg.type) { case MessageType.Connect: ConnectMsg.Process(this, msg); break; case MessageType.Disconnect: DisconnectMsg.Process(this, msg); break; case MessageType.NewLayout: NewLayoutMsg.Process(this, msg); break; case MessageType.RemoveLayout: RemoveLayoutMsg.Process(this, msg); break; case MessageType.NewDevice: NewDeviceMsg.Process(this, msg); break; case MessageType.NewEvents: NewEventsMsg.Process(this, msg); break; case MessageType.ChangeUsages: ChangeUsageMsg.Process(this, msg); break; case MessageType.RemoveDevice: RemoveDeviceMsg.Process(this, msg); break; case MessageType.StartSending: StartSendingMsg.Process(this, msg); break; case MessageType.StopSending: StopSendingMsg.Process(this, msg); break; } }
void OnData(DataStreamReader stream) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg); switch (header.cmd) { case Commands.CONNECTED: ConnectMsg cMsg = JsonUtility.FromJson <ConnectMsg>(recMsg); Debug.Log("[Client] Client connected to the server : " + clientId); break; case Commands.LOGIN: LoginMsg lMsg = JsonUtility.FromJson <LoginMsg>(recMsg); Debug.Log("[Client] Client logged in to the server : " + lMsg.clientId); break; case Commands.PLAYER_SPAWNED: PlayerSpawnMsg psMsg = JsonUtility.FromJson <PlayerSpawnMsg>(recMsg); Debug.Log("[Client] Player Spawn message received! " + psMsg.player.id); GameplayManager.Instance.SpawnPlayer(psMsg.player, true); break; case Commands.PLAYER_UPDATE: PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg); Debug.Log("[Client] Player update message received!"); break; case Commands.SERVER_UPDATE: ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg); //Debug.Log( "[Client] Server update message received!" + suMsg.players.ToArrayString() ); GameplayManager.Instance.UpdatePlayers(suMsg.players, suMsg.playerCommands); break; default: Debug.Log("[Client] Unrecognized message received!"); break; } }
void IObserver <Message> .OnNext(Message msg) { switch (msg.type) { case MessageType.Connect: ConnectMsg.Process(this, msg); break; case MessageType.Disconnect: DisconnectMsg.Process(this, msg); break; case MessageType.NewTemplate: NewTemplateMsg.Process(this, msg); break; case MessageType.RemoveTemplate: RemoveTemplateMsg.Process(this, msg); break; case MessageType.NewDevice: NewDeviceMsg.Process(this, msg); break; case MessageType.NewEvents: NewEventsMsg.Process(this, msg); break; case MessageType.ChangeUsages: ChangeUsageMsg.Process(this, msg); break; case MessageType.RemoveDevice: RemoveDeviceMsg.Process(this, msg); break; } }
private static void OnAttach(ref ConnectMsg msg, MyNetworkClient sender) { MyEntity entity1, entity2; MyEntities.TryGetEntityById(msg.MasterEntityId, out entity1); MyEntities.TryGetEntityById(msg.SlaveEntityId, out entity2); if (entity1 is MyShipConnector && entity2 is MyShipConnector) { var connector1 = entity1 as MyShipConnector; var connector2 = entity2 as MyShipConnector; Matrix matrix1 = Matrix.CreateWorld(msg.MasterTranslation, msg.MasterForward, msg.MasterUp); Matrix matrix2 = Matrix.CreateWorld(msg.SlaveTranslation, msg.SlaveForward, msg.SlaveUp); connector1.ConnectNosync(ref matrix1, ref matrix2, connector2); } }
public static void AnnounceConnect(MyShipConnector masterConnector, MyShipConnector slaveConnector, ref Matrix masterMatrix, ref Matrix slaveMatrix) { var msg = new ConnectMsg(); msg.MasterEntityId = masterConnector.EntityId; msg.SlaveEntityId = slaveConnector.EntityId; msg.MasterForward = masterMatrix.Forward; msg.MasterUp = masterMatrix.Up; msg.MasterTranslation = masterMatrix.Translation; msg.SlaveForward = slaveMatrix.Forward; msg.SlaveUp = slaveMatrix.Up; msg.SlaveTranslation = slaveMatrix.Translation; Sync.Layer.SendMessageToAll(ref msg); }