Exemple #1
0
        private void OnRecvCFriends(IChannel channel, Message message)
        {
            Console.WriteLine("OnRecvCFriends");
            Player        player  = (Player)channel.GetContent();
            ConnectDB     connect = new ConnectDB();
            List <string> friends = connect.GetFriends(player.user);

            if (friends.Count > 0)
            {
                SFriends friendList = new SFriends()
                {
                    friends = new List <string>(friends)
                };
                channel.Send(friendList);
            }
        }
Exemple #2
0
        private void OnRecvPlayerEnter(IChannel channel, Message message)
        {
            CPlayerEnter request = message as CPlayerEnter;
            Player       player  = (Player)channel.GetContent();
            Scene        scene   = World.Instance.GetScene(player.scene);

            // add the player to the scene
            player.Spawn();
            scene.AddEntity(player);

            // send player attributes
            SPlayerAttribute attrMessage = new SPlayerAttribute()
            {
                playerId     = player.entityId,
                name         = player.user,
                currentHP    = player.currentHP,
                level        = player.level,
                intelligence = player.intelligence,
                speed        = player.speed,
                attack       = player.attack,
                defense      = player.defense,
                GoldNum      = player.GoldNum,
                SilverNum    = player.SilverNum
            };

            channel.Send(attrMessage);

            // add online player
            OnlinePlayers.Add(player.user, player);
            // send oneline player to frontend
            Dictionary <int, string> SendDic = new Dictionary <int, string>();

            foreach (KeyValuePair <string, Player> tmp in OnlinePlayers)
            {
                SendDic.Add(tmp.Value.entityId, tmp.Key);
                Console.WriteLine("contains user:{0}", tmp.Key);
            }
            SFindFriends response = new SFindFriends()
            {
                friends = SendDic
            };

            player.Broadcast(response);


            // send treasure attributes
            ConnectDB connect = new ConnectDB();

            if (treasureAttributes.Count == 0)
            {
                treasureAttributes = new Dictionary <string, DTreasure>(connect.GetTreasureAttri());
            }
            STreasureAttribute treasureAttribute = new STreasureAttribute()
            {
                treasureAttri = new Dictionary <string, DTreasure>(treasureAttributes)
            };

            channel.Send(treasureAttribute);

            // send mall
            if (backMall.Count == 0)
            {
                backMall = new Dictionary <string, DTreasureMall>(connect.DBGetMall());
            }
            SMall mall = new SMall()
            {
                goods = new Dictionary <string, DTreasureMall>(backMall)
            };

            channel.Send(mall);

            // send package
            SPackage package = new SPackage()
            {
                goods = new Dictionary <string, DTreasurePackage>(connect.DBGetPackage(player.user))
            };

            channel.Send(package);

            // send friends
            SFriends friendList = new SFriends()
            {
                friends = new List <string>(connect.GetFriends(player.user))
            };

            channel.Send(friendList);

            // send friend requests
            SFindFriendRequests requestList = new SFindFriendRequests()
            {
                requests = new List <string>(connect.GetFriendRequest(player.user))
            };

            channel.Send(requestList);
        }
Exemple #3
0
        private void OnRecvFriends(IChannel channel, Message message)
        {
            SFriends msg = message as SFriends;

            PlayerInfo.friends = new System.Collections.Generic.List <string>(msg.friends);
        }