Exemple #1
0
        private void FightMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var fightMsg = msg as FightMessage;
            var r        = new FightResultMessage();

            if (AdventurePluginDB.User.Get(fightMsg.PlayerId) != null)
            {
                r.Result   = OkTag;
                r.ObjectId = fightMsg.ObjectId;
                var follower = AdventurePluginDB.PlayerFollower.GetPlayerFollower(fightMsg.PlayerId);

                if (follower.FollowerList.Contains(fightMsg.ObjectId))
                {
                    if (fightMsg.FightType == FightMessage.GoToFight)
                    {
                        follower.FightingFollowerList.Add(fightMsg.ObjectId);
                        r.StatusNow = FightMessage.GoToFight;
                    }
                    else
                    {
                        if (follower.FightingFollowerList.Contains(fightMsg.ObjectId))
                        {
                            follower.FightingFollowerList.Remove(fightMsg.ObjectId);
                            r.StatusNow = FightMessage.GoToRest;
                        }
                    }
                }
                AdventurePluginDB.PlayerFollower.Update(follower);
            }
            else
            {
                r.Result = ErrorTag;
            }
            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #2
0
        private void Create(string pipeName, PipeDirection direction, int maxNumberOfServerInstances,
                            PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
                            HandleInheritability inheritability)
        {
            Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
            Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
            Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
            Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
            Debug.Assert((maxNumberOfServerInstances >= 1) || (maxNumberOfServerInstances == MaxAllowedServerInstances), "maxNumberOfServerInstances is invalid");
            Debug.Assert(transmissionMode >= PipeTransmissionMode.Byte && transmissionMode <= PipeTransmissionMode.Message, "transmissionMode is out of range");

            if (transmissionMode == PipeTransmissionMode.Message)
            {
                throw new PlatformNotSupportedException(SR.PlatformNotSupported_MessageTransmissionMode);
            }

            // We don't have a good way to enforce maxNumberOfServerInstances across processes; we only factor it in
            // for streams created in this process.  Between processes, we behave similarly to maxNumberOfServerInstances == 1,
            // in that the second process to come along and create a stream will find the pipe already in existence and will fail.
            _instance = SharedServer.Get(GetPipePath(".", pipeName, IsCurrentUserOnly), maxNumberOfServerInstances);

            _direction      = direction;
            _options        = options;
            _inBufferSize   = inBufferSize;
            _outBufferSize  = outBufferSize;
            _inheritability = inheritability;
        }
Exemple #3
0
        private void HireFollowerMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var hireMsg = msg as HireFollowerMessage;
            var r       = new HireResultMessage();

            if (AdventurePluginDB.User.Get(hireMsg.PlayerId) != null)
            {
                r.Result = OkTag;
                var follower = AdventurePluginDB.PlayerFollower.GetPlayerFollower(hireMsg.PlayerId);

                var ObjectIdList = new List <int>();
                foreach (var id in hireMsg.FollowerId)
                {
                    var objId = ObjectId;
                    r.Followers.Add(new KeyValuePair <int, int>(objId, id));
                    ObjectIdList.Add(objId);

                    var info = new FollowerInfo()
                    {
                        FollowerID = id,
                        ObjectID   = objId,
                    };
                    AdventurePluginDB.Follower.Create(info);
                }

                follower.FollowerList.AddRange(ObjectIdList);
                AdventurePluginDB.PlayerFollower.Update(follower);
            }
            else
            {
                r.Result = ErrorTag;
            }
            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #4
0
        private void SendFarmIncomeMsg(NetConnection conn, int exp, int money)
        {
            var msg = new FarmIncomeMessage()
            {
                Exp   = exp,
                Money = money,
            };

            SharedServer.SendMessage(msg, conn);
        }
Exemple #5
0
        private void GotoMapMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var mapMsg = msg as GotoMapMessage;
            var r      = new GotoResultMessage()
            {
                Level    = mapMsg.Level,
                GoToType = GotoResultMessage.ToMap,
            };

            if (mapMsg.Attact >= mapMsg.AttactNeed)
            {
                AddFarmObj(im.SenderConnection, mapMsg.PlayerId, mapMsg.Money, mapMsg.Exp);
            }

            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #6
0
        private void LoginMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var loginMsg = msg as LoginMessage;
            var r        = new LoginResultMessage();

            var user = AdventurePluginDB.User.Get(loginMsg.Name, loginMsg.Pass);

            if (user != null)
            {
                r.Result   = OkTag;
                r.PlayerId = user.id;
            }
            else
            {
                r.Result = ErrorTag;
            }
            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #7
0
        private void RegisterMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var registerMsg = msg as RegisterMessage;
            var r           = new RegisterResultMessage();

            if (AdventurePluginDB.User.Get(registerMsg.Name, registerMsg.Pass) == null)
            {
                var user = new UserInfo
                {
                    Name = registerMsg.Name,
                    Pass = registerMsg.Pass,
                };
                var id = AdventurePluginDB.User.Create(user);

                const int FreeId = 2; // 赠送路人乙

                var objid = ObjectId;
                var info  = new FollowerInfo()
                {
                    FollowerID = FreeId,
                    ObjectID   = objid,
                };
                AdventurePluginDB.Follower.Create(info);

                AdventurePluginDB.Customer.Create(new CustomerInfo()
                {
                    PlayerId = id,
                });
                AdventurePluginDB.PlayerFollower.Create(new PlayerFollowerInfo()
                {
                    PlayerId     = id,
                    FollowerList = { objid }
                });

                r.PlayerId = id;
                r.Result   = OkTag;
            }
            else
            {
                r.Result = ErrorTag;
            }
            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #8
0
        private void GotoHomeMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var homeMsg = msg as GotoHomeMessage;
            var r       = new GotoResultMessage()
            {
                GoToType = GotoResultMessage.ToHome,
            };

            RemoveFarmObj(im.SenderConnection);
            r.UserData = homeMsg.UserData;
            var customer = AdventurePluginDB.Customer.GetPlayerCustomer(homeMsg.PlayerId);

            if (customer != null)
            {
                r.Exp   = customer.Exp;
                r.Money = customer.Money;
            }

            SharedServer.SendMessage(r, im.SenderConnection);
        }
Exemple #9
0
            internal static SharedServer Get(string path, int maxCount)
            {
                Debug.Assert(!string.IsNullOrEmpty(path));
                Debug.Assert(maxCount >= 1);

                lock (s_servers)
                {
                    SharedServer server;
                    if (s_servers.TryGetValue(path, out server))
                    {
                        // On Windows, if a subsequent server stream is created for the same pipe and with a different
                        // max count, the subsequent count is largely ignored in that it doesn't change the number of
                        // allowed concurrent instances, however that particular instance being created does take its
                        // own into account, so if its creation would put it over either the original or its own limit,
                        // it's an error that results in an exception.  We do the same for Unix here.
                        if (server._currentCount == server._maxCount)
                        {
                            throw new IOException(SR.IO_AllPipeInstancesAreBusy);
                        }
                        else if (server._currentCount == maxCount)
                        {
                            throw new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path));
                        }
                    }
                    else
                    {
                        // No instance exists yet for this path. Create one a new.
                        server = new SharedServer(path, maxCount);
                        s_servers.Add(path, server);
                    }

                    Debug.Assert(server._currentCount >= 0 && server._currentCount < server._maxCount);
                    server._currentCount++;
                    return(server);
                }
            }
Exemple #10
0
        private void PullMessageImpl(NetIncomingMessage im, MessageBase msg)
        {
            var pullMsg = msg as PullMessage;
            var r       = new PushMessage();

            if (AdventurePluginDB.PlayerFollower.IsPlayerExist(pullMsg.PlayerId))
            {
                var follower = AdventurePluginDB.PlayerFollower.GetPlayerFollower(pullMsg.PlayerId);
                r.FollowerList.AddRange(follower.FollowerList.Select(x =>
                {
                    return(new KeyValuePair <int, int>(x, AdventurePluginDB.Follower.GetWithObjectId(x)));
                }));
                r.FightFollowerList.AddRange(follower.FightingFollowerList);

                var customer = AdventurePluginDB.Customer.GetPlayerCustomer(pullMsg.PlayerId);
                if (customer != null)
                {
                    r.Exp   = customer.Exp;
                    r.Money = customer.Money;
                }
            }

            SharedServer.SendMessage(r, im.SenderConnection);
        }