private static void Server_OnReceiveHandler(ConReader reader) { Console.WriteLine("Aguardando"); Console.WriteLine(new { Name = reader.ReadString(), }); }
private static void Server_OnReceiveHandler(IClient client, ConReader reader) { using (ConReader t = reader) { int tag = t.GetTag(); if (client is UDPClient && !clientsUDP.ContainsKey(client)) { Console.WriteLine("Adicionando no UDP"); clientsUDP.Add(client, new Player()); } if (client is TCPClient) { switch (tag) { case 1: int id = t.ReadInt(); string nome = t.ReadString(); float x = t.ReadFloat(); float y = t.ReadFloat(); float z = t.ReadFloat(); bool isLocal = t.ReadBool(); foreach (var p in clientsTCP) { using (ConWriter conWriter = new ConWriter(1)) { conWriter.Send(id); conWriter.Send(nome); conWriter.Send(x); conWriter.Send(y); conWriter.Send(z); conWriter.Send(isLocal); p.Key.Send(conWriter); } } break; case 2: using (ConWriter writer = new ConWriter(2)) { int playerId = t.ReadInt(); KeyValuePair <IClient, Player> player = clientsTCP.First(x1 => { Console.WriteLine(x1.Value.Id + " " + playerId); return(x1.Value.Id == playerId); }); player.Value.Position.X = t.ReadFloat(); player.Value.Position.Y = t.ReadFloat(); player.Value.Position.Z = t.ReadFloat(); writer.Send(player.Value.Id); writer.Send(player.Value.Position.X); writer.Send(player.Value.Position.Y); writer.Send(player.Value.Position.Z); Console.WriteLine("Enviando para todos mensagem de " + player.Value.Id); SendToAll(writer.GetBuffer(), new List <IClient>() { player.Key }); } break; default: break; } } else { int playerId = reader.ReadInt(); switch (tag) { case 1: Console.WriteLine(reader.ReadString()); break; } } } }