public void Enter(User u) { lock (mylock) { m_stack.Add(u); } Packet p = new Packet(); p.addByte(PacketDefine.PlayerInMap); p.addInt(u.id); p.addInt(this.id); p.addInt(u.x); p.addInt(u.y); foreach (User user in m_stack) { user.sendPacket(p); //向玩家发送此玩家进入地图 Packet other = new Packet(); other.addByte(PacketDefine.PlayerInMap); other.addInt(user.id); other.addInt(this.id); other.addInt(user.x); other.addInt(user.y); if (user.id != u.id) { u.sendPacket(other); //向u发送已经存在地图的玩家 } } }
public void Move(User u) { Packet p = new Packet(); p.addByte(PacketDefine.PlayerPositonMove); p.addInt(u.id); p.addInt(this.id); p.addInt(u.x); p.addInt(u.y); foreach (User user in m_stack) { user.sendPacket(p); } }
public void doData(byte[] data) { tempindex = 0; byte command = DataPro.getByte(data, ref tempindex); switch (command) { case PacketDefine.UserIn: isON = true; Packet p = new Packet(); p.addByte(PacketDefine.ConnectionSucess); p.addInt(m_id); Console.WriteLine("玩家: {0}", m_id); sendPacket(p); break; case PacketDefine.EnterMap: Enter(data); break; case PacketDefine.MoveInMap: Move(data); break; } }
public void Leave(User u) { Packet p = new Packet(); p.addByte(PacketDefine.UserLeave); p.addInt(u.id); p.addInt(this.id); foreach (User user in m_stack) { if (user == u) { lock(mylock) { m_stack.Remove(user); break; } } } foreach (User ua in m_stack) { ua.sendPacket(p); } }
public void Leave(User u) { Packet p = new Packet(); p.addByte(PacketDefine.UserLeave); p.addInt(u.id); p.addInt(this.id); foreach (User user in m_stack) { if (user == u) { lock (mylock) { m_stack.Remove(user); break; } } } foreach (User ua in m_stack) { ua.sendPacket(p); } }
public void doData(byte[] data) { tempindex = 0; byte command = DataPro.getByte(data, ref tempindex); switch(command) { case PacketDefine.UserIn: isON = true; Packet p = new Packet(); p.addByte(PacketDefine.ConnectionSucess); p.addInt(m_id); Console.WriteLine("玩家: {0}", m_id); sendPacket(p); break; case PacketDefine.EnterMap: Enter(data); break; case PacketDefine.MoveInMap: Move(data); break; } }