private void HandleGamePacket(object sender,PacketEventArgs e) { INetNode node = (INetNode)sender; if (e.Type == PacketType.Connect) { if (e.Data.Length != 0) return; byte[] data = new byte [8]; BitConv.ToInt32(data,0,nodes.IndexOf(node)); BitConv.ToInt32(data,4,nodes.Count); node.SendPacket(PacketType.Accepted,data); } else if (e.Type == PacketType.DoomData) { if (e.Data.Length < 4) return; int nodeid = BitConv.FromInt32(e.Data,0); if (nodeid < 0 || nodeid >= nodes.Count) return; byte[] data = new byte [e.Data.Length]; BitConv.ToInt32(data,0,nodes.IndexOf(node)); Array.Copy(e.Data,4,data,4,e.Data.Length - 4); nodes[nodeid].SendPacket(PacketType.DoomData,data); } }
private void HandleJoinPacket(object sender,PacketEventArgs e) { INetNode node = (INetNode)sender; if (e.Type == PacketType.Connect) { node.SendPacket(PacketType.Waiting,new byte [0]); } }
public void ReceivePacket(PacketType type,byte[] data) { if (PacketReceived != null) { PacketEventArgs e = new PacketEventArgs(); e.Type = type; e.Data = data; PacketReceived(this,e); } }