private static void Connect(Connection client, NetworkMessage msg) { client.endpoint = Protocol.GetEndPoint(); Creature player = new Creature(client.Id); client.player = player; msg = new NetworkMessage(MsgType.PlayerData); msg.Write(player.GetID()); msg.Write(player.GetPosition()); //msg.Send(client); //Testing foreach (var c in Protocol.connections.Values) { if (c != null) { msg.Send(c); } } foreach (var c in Protocol.connections.Values) { if (c == client) { continue; } Creature p = c.player; NetworkMessage msg2 = new NetworkMessage(MsgType.PlayerData); msg2.Write(p.GetID()); msg2.Write(p.GetPosition()); msg2.Send(client, System.Net.Sockets.ProtocolType.Udp); } }
private static void Ping(Connection client, NetworkMessage msg) { long time = msg.ReadLong(); msg = new NetworkMessage(MsgType.Ping); msg.Write(time); msg.Send(client); }
public void Move(Vector2 direction) { if (direction == Vector2.Zero) return; var dirNormalized = Vector2.Normalize(direction); position += new Vector3(dirNormalized.X, position.Y, dirNormalized.Y) * speed; NetworkMessage msg = new NetworkMessage(MsgType.MoveDirection); msg.Write(id); msg.Write(position); msg.Write(speed); //msg.Send(Protocol.connections[id], ProtocolType.Udp); foreach (var client in Protocol.connections.Values) { msg.Send(client, ProtocolType.Udp); } }