private static bool OnProcessHappyLogin(NetServer server, int id, NetIncomingMessage msg) { var r = new Msg_HappyPlayerLogin(); r.R(msg); uint uid = HappyGameId; int x = RandomMaker.Next(10); int y = RandomMaker.Next(10); uint sid = (uint)RandomMaker.Next(83); var selfMsg = new Msg_HappyPlayerLoginRsp(); selfMsg.Uid = uid; selfMsg.X = x; selfMsg.Y = y; selfMsg.SpriteId = sid; SendMessage(server, selfMsg, msg.SenderConnection); // 更新链接对应的ID HappyConnMgr.Modify(msg.SenderConnection, uid); var playerPackMsg = new Msg_HappyPlayerPack(); // 为新玩家推送旧玩家信息 var playerList = HappyPlayerMgr.ToList(); var playerPackList = from f in playerList select Tuple.Create <uint, int, int, bool, uint>(f.Key, f.Value.X, f.Value.Y, f.Value.IsAlive, f.Value.SpriteId); playerPackMsg.PlayerPack = playerPackList.ToList(); SendMessage(server, playerPackMsg, msg.SenderConnection); // 为旧玩家推送新玩家信息 var otherMsg = new Msg_HappyOtherPlayerLogin(); otherMsg.Uid = uid; otherMsg.X = x; otherMsg.Y = y; otherMsg.SpriteId = sid; SendMessageExceptOne(server, otherMsg, msg.SenderConnection); // 添加新玩家到玩家管理中 var player = new HappyPlayer(); player.X = x; player.Y = y; player.IsAlive = true; player.SpriteId = sid; HappyPlayerMgr.Add(uid, player); return(true); }
private static bool OnProcessBorn(NetServer server, int id, NetIncomingMessage msg) { var r = new Msg_AgarBorn(); r.R(msg); uint uid = r.UserId; string name = r.Name; int x = RandomMaker.Next(GameWidth); int y = RandomMaker.Next(GameHeight); int radius = PlayerBall.DefaultPlayerRadius; uint c = CustomColors.RandomColor; // 添加Player到Manager PlayerBall player = new PlayerBall(); player.X = x; player.Y = y; player.Radius = radius; player.Color = c; player.Name = name; PlayerBallMgr.Add(uid, player); MarkMgr.Update(uid, radius); // 更新链接对应的ID AgarConnMgr.Modify(msg.SenderConnection, uid); // 向自身发送出生位置等信息 var selfMsg = new Msg_AgarSelf(); selfMsg.Operat = Msg_AgarSelf.Born; selfMsg.X = x; selfMsg.Y = y; selfMsg.Radius = radius; selfMsg.Color = c; SendMessage(server, selfMsg, msg.SenderConnection); // 向之前加入的玩家推送新用户出生信息 var oMsg = new Msg_AgarPlayInfo(); oMsg.Operat = Msg_AgarPlayInfo.Add; oMsg.UserId = uid; oMsg.Tag = GameMessageHelper.ALL_TAG; oMsg.X = x; oMsg.Y = y; oMsg.Radius = radius; oMsg.Color = c; oMsg.Name = name; SendMessageExceptOne(server, oMsg, msg.SenderConnection); return(true); }