예제 #1
0
        public static bool ReduceRoomCard(long userID, int number)
        {
            var data = RoomCardBusiness.CreateBuilder().SetUserID(userID.ToString()).SetBusinessID("6").SetCounts(number).Build().ToByteArray();

            try
            {
                var resData = new MySocket(host, port).SendReceive(CreateHead.CreateMessage(10030, data.Length, 0, data));
                if (resData.FirstOrDefault() != null)
                {
                    var status = Result.ParseFrom(resData.FirstOrDefault().Data).Status;
                    if (status == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        MyLogger.Logger.Info("请求扣除房卡" + status);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                MyLogger.Logger.Info("请求扣除房卡:" + ex);
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 根据服务器名称获取并发送给客户端 ip和端口
        /// </summary>
        /// <param name="serverName">服务器名称</param>
        /// <param name="messageNum">收到的消息号</param>
        /// <param name="session"></param>
        /// <param name="status">状态 1为正常切换服务器,2为有牌局为结束</param>
        /// <returns></returns>
        public static bool GetServerIP(string serverName, int messageNum, GameSession session, int status, UserInfo userinfo)
        {
            XmlDocument       doc      = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;//忽略文档里面的注释
            string ip   = string.Empty;
            string port = string.Empty;

            using (var reader = XmlReader.Create(@"ServerNameList.xml", settings))
            {
                doc.Load(reader);
                XmlNode nodeList = doc.SelectSingleNode("servers");
                foreach (XmlNode item in nodeList.ChildNodes)
                {
                    XmlElement xe = (XmlElement)item;
                    if (xe.GetAttribute("name").Equals(serverName))
                    {
                        ip   = xe.ChildNodes[0].InnerText;
                        port = xe.ChildNodes[1].InnerText;
                    }
                }
            }
            if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(port))
            {
                session.Logger.Error(string.Format("服务器配置文件不存在 {0} 服务器", serverName));
                XmlNode nodeList = doc.SelectSingleNode("servers");
                foreach (XmlNode item in nodeList.ChildNodes)
                {
                    XmlElement xe = (XmlElement)item;
                    if (xe.GetAttribute("name").Equals(GameInformationBase.DEFAULTGAMESERVERNAME))
                    {
                        ip   = xe.ChildNodes[0].InnerText;
                        port = xe.ChildNodes[1].InnerText;
                    }
                }
                GetClient().KeyDelete(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, userinfo.openid, userinfo.unionid));
            }
            ReturnServerIP.Builder serverIP = ReturnServerIP.CreateBuilder();
            serverIP.SetIp(ip).SetPort(port).SetStatus(status);
            byte[] serverIPData = serverIP.Build().ToByteArray();
            return(session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1010, serverIPData.Length, messageNum, serverIPData))));
        }