/// <summary>
 ///     Handle a player disconnect event
 /// </summary>
 private static void HandlePlayerDisconnect(string text, OutputParseResult outputparseresult, IPlayerAction playeraction)
 {
     if (OnlinePlayers.ContainsKey(playeraction.PlayerName))
     {
         OnlinePlayers.Remove(playeraction.PlayerName);
     }
     RaisePlayerListChangedEvent();
 }
Beispiel #2
0
        public Player GetPlayer(int entityId)
        {
            if (OnlinePlayers.ContainsKey(entityId))
            {
                return(OnlinePlayers[entityId]);
            }

            return(null);
        }
Beispiel #3
0
 public void RemovePlayer(int entityId)
 {
     lock (OnlinePlayers)
     {
         if (OnlinePlayers.ContainsKey(entityId))
         {
             OnlinePlayers.Remove(entityId);
         }
     }
 }
 /// <summary>
 ///     Remove a player from the online players list and raise the according events
 /// </summary>
 /// <param name="player">The player to remove</param>
 public static void RemovePlayer(Player player)
 {
     if (player == null || !OnlinePlayers.ContainsKey(player.Name))
     {
         return;
     }
     OnlinePlayers.Remove(player.Name);
     RaisePlayerListChangedEvent();
     RaisePlayerListDeletionEvent(player);
 }
        /// <summary>
        ///     Handle a player join event
        /// </summary>
        private static void HandlePlayerJoin(
            string text,
            OutputParseResult outputparseresult,
            IPlayerAction playeraction)
        {
            PlayerActionJoin join = (PlayerActionJoin)playeraction;

            Player player = new Player(join.PlayerName, join.Ip, join.PlayerName)
            {
                JoinTime = @join.Time
            };

            if (!OnlinePlayers.ContainsKey(player.Name))
            {
                OnlinePlayers.Add(player.Name, player);
            }
            RaisePlayerListChangedEvent();
        }
Beispiel #6
0
        private void OnRecvLogin(IChannel channel, Message message)
        {
            CLogin request = message as CLogin;
            string scene   = "Level1";

            // read from database
            ConnectDB connect  = new ConnectDB();
            int       playerID = connect.LogIn(request.user, request.password);

            if (playerID == 0)
            {
                ClientTipInfo(channel, "Wrong UserName or Passwd!");
                return;
            }
            if (OnlinePlayers.ContainsKey(request.user))
            {
                ClientTipInfo(channel, "user has logged in!");
                return;
            }

            SPlayerEnter response = new SPlayerEnter()
            {
                user  = request.user,
                token = request.user,
                scene = scene
            };

            channel.Send(response);

            Player player = new Player(channel)
            {
                scene = scene
            };
            DEntity dentity = World.Instance.EntityData["Ellen"];

            player.FromDEntity(dentity);
            player.forClone = false;
            connect.GetPlayerAttri(playerID, player);
            Console.WriteLine("user: {0} login", player.user);

            // DOTO: Add xyz from db
        }
        /// <summary>
        ///     Add a player to the online players list and raise the according events
        /// </summary>
        /// <param name="player">The player to add</param>
        public static void AddPlayer(Player player)
        {
            if (player == null || string.IsNullOrEmpty(player.Name))
            {
                return;
            }

            try
            {
                if (OnlinePlayers.ContainsKey(player.Name))
                {
                    return;
                }

                OnlinePlayers.Add(player.Name, player);
                RaisePlayerListAdditionEvent(player);
                RaisePlayerListChangedEvent();
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Severe, "PlayerHandler", "Failed to add player: " + player.Name, exception.Message);
            }
        }
 /// <summary>
 ///     Check if a player is listed in the dictionarry of online players
 /// </summary>
 /// <param name="name">The name of the player to check</param>
 /// <returns>Returns true if the player is listed, false if the player isn't found</returns>
 public static Boolean IsPlayerListed(String name)
 {
     return(OnlinePlayers.ContainsKey(name));
 }
Beispiel #9
0
        private void OnRecvBuy(IChannel channel, Message message)
        {
            Console.WriteLine("OnRecvBuy");
            CBuy      request  = message as CBuy;
            Player    player   = (Player)channel.GetContent();
            ConnectDB connect  = new ConnectDB();
            int       tmpJudge = 0;
            string    buyer_   = player.user;
            int       price_;
            string    seller_;
            Dictionary <string, int> newSilverGoods = new Dictionary <string, int>();
            Dictionary <string, int> oldSilverGoods = new Dictionary <string, int>();
            List <string>            goldGoods      = new List <string>();

            // resolve message
            foreach (DTreasureBuy goods in request.Goods)
            {
                if (goods.type == 0)
                {
                    goldGoods.Add(goods.name);
                }
                else if (goods.type == 1)
                {
                    newSilverGoods.Add(goods.name, goods.number);
                }
                else if (goods.type == 2)
                {
                    oldSilverGoods.Add(goods.name, goods.number);
                }
            }

            // transaction for gold treasures
            if (request.totalGold > 0)
            {
                // for each gold treasure is a transaction
                foreach (string goods in goldGoods)
                {
                    SBuyGoldResult goldMessage = new SBuyGoldResult();
                    goldMessage.goodsName = goods;
                    price_  = backMall[goods].price;
                    seller_ = backMall[goods].ownerName;
                    //Console.WriteLine("gold transcation: buyer: " + buyer_ + " seller: " + seller_ + " price: " + price_ + " goods: " + goods);
                    tmpJudge = connect.GoldTransaction(buyer_, seller_, price_, goods);
                    //Console.WriteLine("gold insert result: " + tmpJudge);
                    if (tmpJudge == 0)
                    {
                        goldMessage.success = false;
                    }
                    else
                    {
                        // send to seller
                        if (OnlinePlayers.ContainsKey(seller_))
                        {
                            Player toPlayer = OnlinePlayers[seller_];
                            toPlayer.GoldNum += price_;
                            SSendToSeller sellerMsg = new SSendToSeller()
                            {
                                goldCoin  = toPlayer.GoldNum,
                                goodsName = goods
                            };
                            toPlayer.connection.Send(sellerMsg);
                        }
                        // remove from backMalls
                        backMall.Remove(goods);
                        goldMessage.success = true;
                        // change player's goldCoin
                        player.GoldNum -= price_;
                    }
                    //Console.WriteLine("send goldMessage");
                    player.connection.Send(goldMessage);
                }
            }

            // deal with silver goods
            Console.WriteLine(request.totalSilver);
            if (request.totalSilver > 0)
            {
                // add treasure to package
                if (newSilverGoods.Count != 0)
                {
                    List <string> NewsilverTs = new List <string>();
                    foreach (KeyValuePair <string, int> goods in newSilverGoods)
                    {
                        //Console.WriteLine("new silver: buyer:" + buyer_ + " goods: " + goods.Key + " num: " + goods.Value);
                        NewsilverTs.Add(string.Format("('{0}','{1}','{2}')", buyer_, goods.Key, goods.Value));
                        //connect.AddTrade(goods.Key, "mall", buyer_, goods.Value, backMall[goods.Key].price);
                    }
                    tmpJudge = connect.BuyNewSilverTreasure(NewsilverTs);
                    //Console.WriteLine("new silver insert result: " + tmpJudge);
                }

                if (oldSilverGoods.Count != 0)
                {
                    foreach (KeyValuePair <string, int> goods in oldSilverGoods)
                    {
                        //Console.WriteLine("old silver: buyer:" + buyer_ + " goods: " + goods.Key + " num: " + goods.Value);
                        tmpJudge = connect.UpdateTreasureNum(buyer_, goods.Key, goods.Value);
                        connect.AddTrade(goods.Key, "mall", buyer_, goods.Value, backMall[goods.Key].price);
                        //Console.WriteLine("old silver insert result: " + tmpJudge);
                    }
                }

                // minus silver coins
                //Console.WriteLine("silverNum update result: " + tmpJudge);
                player.SilverNum -= request.totalSilver;
                //Console.WriteLine("player: " + buyer_ + " silverNum minus: " + request.totalSilver);
                tmpJudge = connect.UpdateSilverNum(buyer_, player.SilverNum);
            }
        }