Example #1
0
        /// <summary>
        /// 类型:方法
        /// 名称:TryEnter
        /// 作者:taixihuase
        /// 作用:通过角色数据尝试进入场景
        /// 编写日期:2015/7/22
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        /// <param name="peer"></param>
        private static void TryEnter(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            ServerPeer.Log.Debug("Entering");

            int uniqueId = (int)
                Serialization.Deserialize(operationRequest.Parameters[(byte) ParameterCode.WorldEnter]);

            Character character;
            if (peer.Server.Characters.CharacterEnter(uniqueId, out character))
            {
                peer.Server.Data.CharacterData.GetCharacterPosition(character);
            }

            // 返回数据给客户端

            byte[] pos = Serialization.Serialize(character.Position);

            OperationResponse reponseData = new OperationResponse((byte) OperationCode.WorldEnter,
                new Dictionary<byte, object>
                {
                    {(byte) ParameterCode.WorldEnter, pos}
                })
            {
                ReturnCode = (short) ErrorCode.Ok,
                DebugMessage = "进入场景成功"
            };
            peer.SendOperationResponse(reponseData, sendParameters);

            byte[] data = Serialization.Serialize(character);
            EventData eventData = new EventData((byte) EventCode.WorldEnter, new Dictionary<byte, object>
            {
                {(byte) ParameterCode.WorldEnter, data}
            });
            eventData.SendTo(peer.Server.Characters.GamingClientsToBroadcast, sendParameters);
        }
Example #2
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("OnOperationRequest. Code={0}", operationRequest.OperationCode);
            }

            switch (operationRequest.OperationCode)
            {
                case (byte)MyOperationCodes.EchoOperation:
                    {
                        // The echo operation one is handled immediately because it does not require the client to join a game.
                        var myEchoRequest = new MyEchoRequest(this.Protocol, operationRequest);
                        if (this.ValidateOperation(myEchoRequest, sendParameters) == false)
                        {
                            return;
                        }

                        var myEchoResponse = new MyEchoResponse { Response = myEchoRequest.Text };
                        var operationResponse = new OperationResponse(operationRequest.OperationCode, myEchoResponse);
                        this.SendOperationResponse(operationResponse, sendParameters);
                        break;
                    }

                default:
                    {
                        // for this example all other operations will handled by the base class
                        base.OnOperationRequest(operationRequest, sendParameters);
                        return;
                    }
            }
        }
        protected override void OnOperationRequest(OperationRequest request, SendParameters sendParameters)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("OnOperationRequest: pid={0}, op={1}", this.ConnectionId, request.OperationCode);
            }

            switch ((OperationCode)request.OperationCode)
            {
                default:
                    var response = new OperationResponse(request.OperationCode) { ReturnCode = (short)ErrorCode.OperationInvalid, DebugMessage = "Unknown operation code" };
                    this.SendOperationResponse(response, sendParameters);
                    break;

                case OperationCode.Authenticate:
                    OperationResponse authenticateResponse = this.HandleAuthenticate(request);
                    this.SendOperationResponse(authenticateResponse, sendParameters);
                    break;

                case OperationCode.CreateGame:
                case OperationCode.JoinLobby:
                case OperationCode.LeaveLobby:
                case OperationCode.JoinRandomGame:
                case OperationCode.JoinGame:
                    this.lobby.EnqueueOperation(this, request, sendParameters);
                    break;
            }
        }
Example #4
0
 public void OnBroadcastMessage(GamePeer peer, EventData eventData, SendParameters sendParameters)
 {
     if (peer != this)
     {
         this.SendEvent(eventData, sendParameters);
     }
 }
 public void AuthenticateClient(ICustomAuthPeer peer, IAuthenticateRequest authRequest, AuthSettings authSettings, SendParameters sendParameters, object state)
 {
     //TBD: why are we enqueuing could be done on the peers fiber
     this.fiber.Enqueue(() =>
         this.OnAuthenticateClient(peer, authRequest, authSettings, sendParameters, state)
     );
 }
Example #6
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
                default:
                    {
                        string message = string.Format("Unknown operation code {0}", operationRequest.OperationCode);
                        this.SendOperationResponse(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = message }, sendParameters);
                        break;
                    }

                case 1:
                    {
                        var pingOperation = new LatencyOperation(this.Protocol, operationRequest.Parameters);
                        if (pingOperation.IsValid == false)
                        {
                            this.SendOperationResponse(new OperationResponse { OperationCode = operationRequest.OperationCode, ReturnCode = -1, DebugMessage = pingOperation.GetErrorMessage() }, sendParameters);
                            return;
                        }

                        Thread.Sleep(5);

                        var response = new OperationResponse(operationRequest.OperationCode, pingOperation);
                        this.SendOperationResponse(response, sendParameters);
                        break;
                    }
            }
        }
Example #7
0
        protected override void OnOperationRequest(OperationRequest request, SendParameters sendParameters)
        {
            switch (request.OperationCode)
            {
                case (byte)OperationCode.Authenticate:
                    this.HandleAuthenticateOperation(request, sendParameters);
                    return;

                case (byte)OperationCode.CreateGame:
                    this.HandleCreateGameOperation(request, sendParameters);
                    return;

                case (byte)OperationCode.JoinGame:
                    this.HandleJoinGameOperation(request, sendParameters);
                    return;

                case (byte)Lite.Operations.OperationCode.Leave:
                    this.HandleLeaveOperation(request, sendParameters);
                    return;

                case (byte)Lite.Operations.OperationCode.Ping:
                    this.HandlePingOperation(request, sendParameters);
                    return;

                case (byte)OperationCode.DebugGame:
                    this.HandleDebugGameOperation(request, sendParameters);
                    return;

                case (byte)SPOperationCode.UpdateFlightControls:
                this.HandleGameOperation(request, sendParameters);
                    return;
            }

            base.OnOperationRequest(request, sendParameters);
        }
Example #8
0
        public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest);
            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey);
            string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }";

            PlayerInfo info = JsonConvert.DeserializeObject<PlayerInfo>(playerInfoStr);

            PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey));

            var room = FindRoom(joinRequest.RoomID);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info));
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } });
                peer.SendOperationResponse(response, sendParameters);
            }
        }
Example #9
0
        public virtual void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
                case CommonOperationCode.Join:
                    HandleJoinOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.Exit:
                    HandleExitOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.Chat:
                    HandleChatOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.GetRooms:
                    SendAllRoomStatus(peer, sendParameters);
                    break;

                case CommonOperationCode.ConfirmJoin:
                    var task = HandleConfirmJoinOperation(peer, operationRequest, sendParameters);
                    task.Wait();
                    break;
            }
        }
Example #10
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            WriteLog("Receive RequestCode:" + (OperationCode) operationRequest.OperationCode);
            HandlerBase handler;
            ArpgApplication.Instance.Handlers.TryGetValue(operationRequest.OperationCode, out handler);

            if (handler != null)
            {
                //1.处理
                var response = handler.OnHandlerMeesage(operationRequest, this);

                //2.发送响应
                SendOperationResponse(response, sendParameters);

                //3.日志记录
                object subCode = null;
                WriteLog(string.Format("Rsponse operationCode:{0} success",
                    (OperationCode) operationRequest.OperationCode));
            }
            else
            {
                //1.异常,日志记录
                WriteLog(string.Format("Can not find OperationCode:{0}",
                    (OperationCode) operationRequest.OperationCode));
            }
        }
Example #11
0
 private void OnBroadcastMessage(ChatPeer peer, EventData @event, SendParameters sendParameters)
 {
     if (peer != this)
     {
         this.SendEvent(@event, sendParameters);
     }
 }
Example #12
0
        /// <summary>
        /// 类型:方法
        /// 名称:TryRegist
        /// 作者:taixihuase
        /// 作用:通过请求的角色数据,尝试创建、记录一个新的角色数据并再次返回给客户端
        /// 编写日期:2015/7/14
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        /// <param name="peer"></param>
        private static void TryRegist(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            ServerPeer.Log.Debug("Regist a new account...");

            RegistInfo info = (RegistInfo)
                Serialization.Deserialize(operationRequest.Parameters[(byte) ParameterCode.Regist]);

            UserCollection.UserReturn userReturn = peer.Server.Users.RegistUser(info);

            if (userReturn.ReturnCode == UserCollection.UserReturn.ReturnCodeType.Success)
            {
                OperationResponse response = new OperationResponse((byte)OperationCode.Regist)
                {
                    ReturnCode = (short)ErrorCode.Ok,
                    DebugMessage = "账号创建成功!"
                };

                peer.SendOperationResponse(response, sendParameters);
            }
            else
            {
                OperationResponse response = new OperationResponse((byte)OperationCode.Regist)
                {
                    ReturnCode = (short)ErrorCode.InvalidOperation,
                    DebugMessage = userReturn.DebugMessage.ToString()
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(DateTime.Now + " : Failed to regist " + info.Account + " Because of " +
                                     Enum.GetName(typeof(UserCollection.UserReturn.ReturnCodeType),
                                         userReturn.ReturnCode));
            }
        }
        /// <summary>
        ///   Joins the peer to a <see cref = "LiteLobbyGame" />.
        ///   Called by <see cref = "HandleJoinOperation">HandleJoinOperation</see>.
        /// </summary>
        /// <param name = "joinOperation">
        ///   The join operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected virtual void HandleJoinGameWithLobby(JoinRequest joinOperation, SendParameters sendParameters)
        {
            // remove the peer from current game if the peer
            // allready joined another game
            this.RemovePeerFromCurrentRoom();

            RoomReference gameReference = null;
            if (joinOperation.ActorNr == 0)
            {
                // get a game reference from the game cache 
                // the game will be created by the cache if it does not exists allready
                gameReference = LiteLobbyGameCache.Instance.GetRoomReference(joinOperation.GameId, this, joinOperation.LobbyId);

            }
            else
            {
                if (!LiteLobbyGameCache.Instance.TryGetRoomReference(joinOperation.GameId, this, out gameReference))
                {
                    SendOperationResponse(
                        new OperationResponse
                        {
                            OperationCode = joinOperation.OperationRequest.OperationCode,
                            ReturnCode = -1,
                            DebugMessage = "the specified game is not exists."
                        },
                        sendParameters);
                    return;
                }
            }
            // save the game reference in peers state                    
            this.RoomReference = gameReference;

            // enqueue the operation request into the games execution queue
            gameReference.Room.EnqueueOperation(this, joinOperation.OperationRequest, sendParameters);
        }
Example #14
0
        public override void OnHandlerMessage(Photon.SocketServer.OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            SubCode subCode = ParameterTool.GetParameter<SubCode>(request.Parameters,ParameterCode.SubCode,false);
            //给response参数添加subCode
            response.Parameters.Add((byte) ParameterCode.SubCode,subCode);

            switch (subCode)
            {
                case SubCode.AddTaskDB:
                    TaskDB taskDB = ParameterTool.GetParameter<TaskDB>(request.Parameters, ParameterCode.TaskDB);
                    taskDB.Role = peer.LoginRole;
                    taskDBManager.AddTaskDB(taskDB);
                    taskDB.Role = null;
                    ParameterTool.AddParameter(response.Parameters,ParameterCode.TaskDB, taskDB);
                    response.ReturnCode = (short) ReturnCode.Success;
                    break;
                case SubCode.GetTaskDB:
                    List<TaskDB> list = taskDBManager.GetTaskDBList(peer.LoginRole);
                    foreach (var taskDb in list)
                    {
                        taskDb.Role = null;
                    }
                    ParameterTool.AddParameter(response.Parameters,ParameterCode.TaskDBList, list);
                    response.ReturnCode = (short) ReturnCode.Success;
                    break;
                case SubCode.UpdateTaskDB:
                    TaskDB taskDB2 = ParameterTool.GetParameter<TaskDB>(request.Parameters, ParameterCode.TaskDB);
                    taskDB2.Role = peer.LoginRole;
                    taskDBManager.UpdataTaskDB(taskDB2);
                    response.ReturnCode = (short) ReturnCode.Success;
                    break;
            }
        }
Example #15
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var operationCode = (OperationCode) operationRequest.OperationCode;

            if (_context == null)
            {
                if (operationCode != OperationCode.SetupContext)
                    throw new ArgumentException($"Failed to process operation request '{operationCode}', the context has not been initialized");

                var contextType = (ContextType) operationRequest.Parameters[(byte) OperationParameterCode.ContextType];

                if (contextType == ContextType.InstanceServer)
                    _context = new InstanceClientContext(_application, this);
                else if (contextType == ContextType.RegionServer)
                    _context = new RegionClientContext(_application, this);
                else if (contextType == ContextType.PlayerClient)
                    _context = new PlayerClientContext(_application, this);
                else if (contextType == ContextType.ConsoleClient)
                    _context = new ConsoleClientContext(_application, this);
                else
                    throw new ArgumentException($"Failed setup context type '{contextType}', the context type was not recognized");

                return;
            }

            _context.OnOperationRequest(operationCode, operationRequest.Parameters);
        }
 public void BroadcastEvent(IEventData evt, SendParameters param)
 {
     foreach (StarCollectorPeer peer in listPeer)
     {
         peer.SendEvent(evt, param);
     }
 }
 public void OnOperationRequest(StarCollectorPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
 {
     executionFiber.Enqueue(() =>
     {
         this.ProcessMessage(sender,
             operationRequest, sendParameters);
     });
 }
Example #18
0
 private void broadcastNewInLobby()
 {
     var sp = new SendParameters();
     sp.Flush = true;
     sp.Unreliable = false;
     AllRoomsBroadcast(null, new OperationRequest(), new SendParameters(),
                       (byte) DiscussionEventCode.InstantUserPlusMinus);
 }
 protected override void OnAuthenticateClient(
     ICustomAuthPeer peer, 
     IAuthenticateRequest authRequest, 
     AuthSettings authSettings,
     SendParameters sendParameters, object state)
 {
     base.OnAuthenticateClient(peer, authRequest, authSettings, sendParameters, state);
 }
Example #20
0
 protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
 {
     World.Instance.RemoveClient(this);
     var sendParameters = new SendParameters();
     sendParameters.Unreliable = true;
     WorldExitHandler(sendParameters);
     Log.Debug("Disconnected!");
 }
Example #21
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch ((DiscussionOpCode) operationRequest.OperationCode)
            {
                case DiscussionOpCode.Test:
                    var operation = new TestOperation(this.Protocol, operationRequest);
                    if (ValidateOperation(operation, sendParameters))
                    {
                        SendOperationResponse(operation.GetResponse(), sendParameters);
                        return;
                    }
                    break;
                case DiscussionOpCode.NotifyUserAccPlusMinus:
                case DiscussionOpCode.NotifyStructureChanged:
                case DiscussionOpCode.NotifyArgPointChanged:
                case DiscussionOpCode.CursorRequest:
                case DiscussionOpCode.CreateShapeRequest:
                case DiscussionOpCode.DeleteShapesRequest:
                case DiscussionOpCode.UnselectAllRequest:
                case DiscussionOpCode.DeleteSingleShapeRequest:
                case DiscussionOpCode.StateSyncRequest:
                case DiscussionOpCode.InitialSceneLoadRequest:
                case DiscussionOpCode.LinkCreateRequest:
                case DiscussionOpCode.UnclusterBadgeRequest:
                case DiscussionOpCode.ClusterBadgeRequest:
                case DiscussionOpCode.ClusterMoveRequest:
                case DiscussionOpCode.InkRequest:
                case DiscussionOpCode.DEditorReport:
                case DiscussionOpCode.ClusterStatsRequest:
                case DiscussionOpCode.LinkReportRequest:
                case DiscussionOpCode.BadgeViewRequest:
                case DiscussionOpCode.ExplanationModeSyncViewRequest:
                case DiscussionOpCode.CommentReadRequest:
                case DiscussionOpCode.AttachLaserPointerRequest:
                case DiscussionOpCode.DetachLaserPointerRequest:
                case DiscussionOpCode.LaserPointerMovedRequest:
                case DiscussionOpCode.ImageViewerManipulateRequest:
                case DiscussionOpCode.ImageViewerStateRequest:
                case DiscussionOpCode.BrowserScrollChanged:
                case DiscussionOpCode.GetBrowserScrollPos:
                case DiscussionOpCode.PdfScrollChanged:
                case DiscussionOpCode.GetPdfScrollPos:  
                    HandleGameOperation(operationRequest, sendParameters);
                    break;
                case DiscussionOpCode.NotifyLeaveUser:
                    handleOnlineStatus(_photonPer, _dbId, false, (int) DeviceType.Sticky);
                    break;
                case DiscussionOpCode.StatsEvent:
                    if (LogEvent(operationRequest.Parameters))
                        HandleGameOperation(operationRequest, sendParameters); // broadcast stats event
                    break;
                case DiscussionOpCode.ScreenshotRequest:
                    HandleScreenshotRequest(operationRequest, sendParameters);
                    break;            
            }

            base.OnOperationRequest(operationRequest, sendParameters);
        }
Example #22
0
 protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
 {
     switch (operationRequest.OperationCode)
     {
         case LGOperationCode.GetRooms:
             //GameServerManager.gameCore.SendAllRoomStatus(this, sendParameters);
             break;
     }
 }
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            IPhotonRequestHandler handler;

            if (RequestHandlers.TryGetValue(operationRequest.OperationCode, out handler))
            {
                handler.HandleRequest(operationRequest);
            }
        }
        protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
        {
            IPhotonEventHandler handler;

            if (EventHandlers.TryGetValue(eventData.Code, out handler))
            {
                handler.HandleEvent(eventData as EventData);
            }
        }
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            IPhotonResponseHandler handler;

            if (ResponseHandlers.TryGetValue(operationResponse.OperationCode, out handler))
            {
                handler.HandleResponse(operationResponse);
            }
        }
        /// <summary>
        /// Kicks the actor from the world (event WorldExited is sent to the client) and then disconnects the client.
        /// </summary>
        /// <remarks>
        /// Called by DisconnectByOtherPeer after being enqueued to the PeerBase.RequestFiber.
        /// It kicks the actor from the world (event WorldExited) and then continues the original request by calling the original peer's OnOperationRequest method.        
        /// </remarks>
        public void OnDisconnectByOtherPeer(PeerBase otherPeer, OperationRequest otherRequest, SendParameters sendParameters)
        {
            this.ExitWorld();

            // disconnect peer after the exit world event is sent
            this.Peer.RequestFiber.Enqueue(() => this.Peer.RequestFiber.Enqueue(this.Peer.Disconnect));

            // continue execution of other request
            PeerHelper.InvokeOnOperationRequest(otherPeer, otherRequest, sendParameters);
        }
Example #27
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
                case OperationCode.Refresh:

                    break;
            }
            // implement this if the outbound side should receive operation data
        }
Example #28
0
        public override void RemovePlayer(GamePeer peer, ExitRequest exitReq, SendParameters sendParameters)
        {
            BaccaratPlayer player = playerManager.GetPlayer(peer) as BaccaratPlayer;
            playersBetDic.Remove(player);
            seatsDic.Remove(player.seat);

            base.RemovePlayer(peer, exitReq, sendParameters);

            CheckAllBet();
        }
        public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            SubCode subcode = ParameterTool.GetParameter<SubCode>(request.Parameters, ParameterCode.SubCode, false);
            ParameterTool.AddParameter(response.Parameters,ParameterCode.SubCode,subcode, false);
            switch (subcode)
            {
                //查询
                case SubCode.GetInventoryItemDB:
                   List<InventoryItemDB> list =  inventoryItemDbManager.GetInventoryDB(peer.LoginRole);
                    foreach (var temp in list)
                    {
                        temp.Role = null;
                    }
                    ParameterTool.AddParameter(response.Parameters,ParameterCode.InventoryItemDBList,list);
                    break;

                //添加
                case SubCode.AddInventoryItemDB:
                    InventoryItemDB itemDB = ParameterTool.GetParameter<InventoryItemDB>(request.Parameters,ParameterCode.InventoryItemDB);
                    itemDB.Role = peer.LoginRole;
                    inventoryItemDbManager.AddInventoryItemDB(itemDB);
                    itemDB.Role = null;
                    ParameterTool.AddParameter(response.Parameters,ParameterCode.InventoryItemDB, itemDB);
                    response.ReturnCode = (short) ReturnCode.Success;
                    break;

                    //更新,一个的情况
                case SubCode.UpdateInventoryItemDB:
                    InventoryItemDB itemDB2 = ParameterTool.GetParameter<InventoryItemDB>(request.Parameters, ParameterCode.InventoryItemDB);
                     itemDB2.Role = peer.LoginRole;
                     inventoryItemDbManager.UpdateInventoryItemDB(itemDB2);
                     break;

                    //更新穿上和卸下的装备,两个的情况
                case SubCode.UpdateInventoryItemDBList:
                    List<InventoryItemDB> list2 = ParameterTool.GetParameter<List<InventoryItemDB>>(request.Parameters,ParameterCode.InventoryItemDBList);
                    foreach (var itemDB3 in list2)
                    {
                        itemDB3.Role = peer.LoginRole;
                    }
                    inventoryItemDbManager.UpdateInventoryItemDBList(list2);
                    break;

                    //升级装备
                case SubCode.UpgradeEquip:
                    InventoryItemDB itemDB4 = ParameterTool.GetParameter<InventoryItemDB>(request.Parameters,ParameterCode.InventoryItemDB);
                    Role role = ParameterTool.GetParameter<Role>(request.Parameters, ParameterCode.Role);
                    peer.LoginRole = role;
                    role.User = peer.LoginUser;
                    itemDB4.Role = role;
                    inventoryItemDbManager.UpgradeEquip(itemDB4, role);
                    break;
            }
        }
Example #30
0
    protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
    {
        var @event = new EventData(1) { Parameters = operationRequest.Parameters };
        lock (syncRoot)
        {
            BroadcastMessage(this, @event, sendParameters);
        }

        var response = new OperationResponse(operationRequest.OperationCode);
        this.SendOperationResponse(response, sendParameters);
    }
Example #31
0
 protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
 {
     CurrentState.OnRecvOperation((EPacketID)operationRequest.OperationCode, operationRequest.Parameters);
 }
Example #32
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            log.Debug("Server get client operation request.");

            HandlerBase handler;

            TeamFightApplication.Instance.m_handlers.TryGetValue(operationRequest.OperationCode, out handler);
            OperationResponse response = new OperationResponse();

            response.OperationCode = operationRequest.OperationCode;
            response.Parameters    = new Dictionary <byte, object>();
            if (handler != null)
            {
                handler.OnHandlerMessage(operationRequest, response, this, sendParameters);
                SendOperationResponse(response, sendParameters);
            }
            else
            {
                log.Debug("Can't find handler from operation code : " + operationRequest.OperationCode);
            }
        }
Example #33
0
        public override OperationResponse Handle(MmoActor actor, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new Operation();

            operation.OnStart();

            ExitWorld(actor);

            // don't send response
            operation.OnComplete();
            return(null);
        }
Example #34
0
 public void SendEvent(EventData eventData, SendParameters sendParameters)
 {
     _peer.SendEvent(eventData, sendParameters);
 }
Example #35
0
 /// <summary>
 ///   This method is invoked sequentially for each operation request
 ///   enqueued in the <see cref = "ExecutionFiber" /> using the
 ///   <see cref = "EnqueueOperation" /> method.
 /// </summary>
 /// <param name = "peer">
 ///   The peer.
 /// </param>
 /// <param name = "operation">
 ///   The operation request.
 /// </param>
 /// <param name = "sendParameters">
 ///   The send Parameters.
 /// </param>
 protected virtual void ExecuteOperation(LitePeer peer, OperationRequest operation, SendParameters sendParameters)
 {
 }
Example #36
0
        public virtual void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
            case CommonOperationCode.Join:
                HandleJoinOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.Exit:
                HandleExitOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.Chat:
                HandleChatOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.GetRooms:
                SendAllRoomStatus(peer, sendParameters);
                break;

            case CommonOperationCode.ConfirmJoin:
                var task = HandleConfirmJoinOperation(peer, operationRequest, sendParameters);
                task.Wait();
                break;
            }
        }
Example #37
0
        /// <summary>
        /// 同步角色移动动画
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="peer"></param>
        /// <param name="sendParameters"></param>
        void SyncRoleMoveAnim(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            Dictionary <byte, object> m_dic = request.Parameters;
            object value;

            // 客户端传递过来的参数信息:角色ID,坐标:X,Y,Z  Y轴旋转:_rY
            if (m_dic.TryGetValue((byte)ParameterCode.SyncInfo, out value))
            {
                string strValue = value.ToString();
                Helper.Log("SyncRoleMoveAnim:" + strValue);
                string[] pStr1 = strValue.Split(',');
                if (pStr1.Length == 2)
                {
                    if (null == peer.m_myTeam)
                    {
                        return;
                    }
                    List <ClientPeer> pTeam = peer.m_myTeam.m_pTeam;
                    if (pTeam == null)
                    {
                        return;
                    }
                    // 通知队伍中的其他Peer返回队伍角色信息给客户端
                    for (int k = 0; k < pTeam.Count; ++k)
                    {
                        ClientPeer curPeer = pTeam[k];
                        if (curPeer != peer)
                        {
                            EventData eventData = new EventData();
                            eventData.Parameters = m_dic;
                            // 返回操作码
                            eventData.Code = (byte)OperationCode.SyncMoveAnim;
                            curPeer.SendEvent(eventData, new SendParameters());
                            //Helper.Log(curPeer.m_curRole.Name + "--:同步:"+peer.m_curRole.Name+"-移动动画信息:" + strValue);
                        }
                    }
                }
            }
        }
Example #38
0
        public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            List <ServerProperty> list = manager.GetServerList();
            string json = JsonMapper.ToJson(list);
            Dictionary <byte, object> parameters = response.Parameters;

            parameters.Add((byte)ParameterCode.ServerList, json);

            response.OperationCode = request.OperationCode;
            response.Parameters    = parameters;
        }
Example #39
0
        public void HandleJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new JoinRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            var room = FindRoom(joinRequest.RoomID);

            var response = new OperationResponse(CommonOperationCode.Join,
                                                 new Dictionary <byte, object> {
                { (byte)CommonParameterKey.Success, false }
            });

            response.Parameters[(byte)JoinParameterKey.RoomID] = joinRequest.RoomID;

            if (room != null && room.CanJoin(peer))
            {
                response.Parameters[(byte)CommonParameterKey.Success] = true;
            }
            peer.SendOperationResponse(response, sendParameters);
        }
Example #40
0
 internal HubContext(HubDescriptor hub, SendParameters sendParameters)
 {
     this.Hub            = hub;
     this.SendParameters = sendParameters;
 }
Example #41
0
 internal HubContext(HubDescriptor hub)
 {
     this.Hub            = hub;
     this.SendParameters = default(SendParameters);
 }
Example #42
0
        public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            User user   = ParameterTool.GetParameter <User>(request.Parameters, ParameterCode.User);
            User userDB = manager.GetUserByUsernmae(user.Username);

            if (userDB != null)
            {
                response.ReturnCode   = (short)ReturnCode.Fail;
                response.DebugMessage = "用户名重复";
            }
            else
            {
                user.Password = MD5Tool.GetMD5(user.Password);
                manager.AddUser(user);
                response.ReturnCode = (short)ReturnCode.Success;
            }
        }
Example #43
0
        /// <summary>
        ///   Publishes an event to a single actor on a specified channel.
        /// </summary>
        /// <param name = "e">
        ///   The event to publish.
        /// </param>
        /// <param name = "actor">
        ///   The <see cref = "Actor" /> who should receive the event.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected void PublishEvent(LiteEventBase e, Actor actor, SendParameters sendParameters)
        {
            var eventData = new EventData(e.Code, e);

            actor.Peer.SendEvent(eventData, sendParameters);
        }
Example #44
0
        public void HandleChatOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var chatRequest = new ChatRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(chatRequest, sendParameters))
            {
                return;
            }

            var room = FindPeerRoom(peer);

            if (room != null)
            {
                room.Chat(peer, chatRequest, sendParameters);
            }
        }
Example #45
0
 /// <summary>
 ///   Enqueues an <see cref = "OperationRequest" /> to the end of the execution queue.
 /// </summary>
 /// <param name = "peer">
 ///   The peer.
 /// </param>
 /// <param name = "operationRequest">
 ///   The operation request to enqueue.
 /// </param>
 /// <param name = "sendParameters">
 ///   The send Parameters.
 /// </param>
 /// <remarks>
 ///   <see cref = "ExecuteOperation" /> is called sequentially for each operation request
 ///   stored in the execution queue.
 ///   Using an execution queue ensures that operation request are processed in order
 ///   and sequentially to prevent object synchronization (multi threading).
 /// </remarks>
 public void EnqueueOperation(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
 {
     this.ExecutionFiber.Enqueue(() => this.ExecuteOperation(peer, operationRequest, sendParameters));
 }
Example #46
0
        public void HandleExitOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var exitRequest = new ExitRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(exitRequest, sendParameters))
            {
                return;
            }

            var room = FindPeerRoom(peer);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Leave(peer));
            }
            peer.Leave();
        }
Example #47
0
 public void SendOperationResponse(OperationResponse response, SendParameters sendParameters)
 {
     _peer.SendOperationResponse(response, sendParameters);
 }
Example #48
0
 public bool ReceiveEvent(EventData eventData, SendParameters sendParameters)
 {
     this.owner.Peer.SendEvent(eventData, sendParameters);
     return(true);
 }
Example #49
0
 public void SendOperationRequest(OperationRequest request, SendParameters sendParameters)
 {
     _peer.SendOperationRequest(request, sendParameters);
 }
        //客户端请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.m_handlerDic, (OperationCode)operationRequest.OperationCode);

            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.m_handlerDic, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
Example #51
0
 public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer clientPeer)
 {
 }
Example #52
0
 protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
 {
     //TODO: Logging, we shouldn't recieve requests.
 }
Example #53
0
        //处理客户端的请求
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            //OperationRequest封装了请求的信息
            //SendParameters 参数,传递的数据


            //通过客户端的OperationCode从HandlerDict里面获取到了需要的Hander
            BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode);

            //如果找到了需要的hander就调用我们hander里面处理请求的方法
            if (handler != null)
            {
                handler.OnOperationRequest(operationRequest, sendParameters, this);
            }
            else//否则我们就使用默认的hander
            {
                BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, OperationCode.Default);
                defaultHandler.OnOperationRequest(operationRequest, sendParameters, this);
            }
        }
Example #54
0
        protected override void OnOperationResponse(OperationResponse operationResponse, SendParameters sendParameters)
        {
            //Try to get the only parameter
            //Should be the RequestMessage
            KeyValuePair <byte, object> objectPair = operationResponse.Parameters.FirstOrDefault();

            //TODO: Easyception should offer Now() ctors
            Throw <InvalidOperationException> .If.IsTrue(objectPair.Value == null)?.Now();

            ResponseMessage message = deserializer.Deserialize <ResponseMessage>(objectPair.Value as byte[]);

            //TODO: Easyception should offer Now() ctors
            Throw <InvalidOperationException> .If.IsTrue(message == null)?.Now();

            //TODO: Handle decryption
            message.Payload.Deserialize(deserializer);

            networkReciever.OnNetworkMessageReceive(message, new PhotonMessageParametersAdapter(sendParameters));
        }
Example #55
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            Log.Debug("!!! STPhotonServer Recv Operation: " + operationRequest.OperationCode);
            //foreach(KeyValuePair<byte,Object> keypair in operationRequest.Parameters)
            //{
            //    Log.Debug(keypair.Key.ToString()+" - "+keypair.Value.ToString());
            //}

            //Console.WriteLine("STPhotonServer Recv Request: " + operationRequest.OperationCode);

            switch (operationRequest.OperationCode)
            {
            case 230:     // user log in

                Log.Warn("------------------- User LogIn !");
                //var info_param=new Dictionary<byte,object>{{1,game_app.cur_game},{2,game_app.checkAvailable()}};
                var info_param = new Dictionary <byte, object>();
                OperationResponse info_response = new OperationResponse((byte)STServerCode.CLogin_Success, info_param)
                {
                    ReturnCode   = (short)0,
                    DebugMessage = "server feedback"
                };
                this.fiber.Enqueue(() => SendOperationResponse(info_response, new SendParameters()));

                break;

            case 253:     //raise event:

                int ievent = Convert.ToInt32(operationRequest.Parameters[244]);

                //Log.Warn("Get Event: "+ievent);

                STClientCode event_code = (STClientCode)(ievent & 0xFF);
                Log.Warn("---------Get Event: " + event_code.ToString() + "---------- ");

                Object oparams = operationRequest.Parameters[245];
                //Log.Warn("params type: "+oparams.GetType());

                Hashtable eparams = (Hashtable)(operationRequest.Parameters[245]);

                Dictionary <byte, Object> event_params = new Dictionary <byte, Object>();
                if (eparams != null)
                {
                    foreach (DictionaryEntry entry in eparams)
                    {
                        try
                        {
                            Log.Debug(entry.Key + " " + entry.Key.GetType() + " - " + entry.Value + " " + entry.Value.GetType());
                        }
                        catch (Exception e)
                        {
                            Log.Error(e.ToString());
                        }
                        byte kbyte;
                        try{
                            kbyte = (byte)entry.Key;
                        }catch (InvalidCastException e) {
                            byte[] bkey = BitConverter.GetBytes((int)entry.Key);
                            Log.Debug("Unable to cast: " + bkey);
                            kbyte = bkey[0];
                        }

                        event_params.Add((byte)kbyte, entry.Value);
                    }
                }
                Log.Warn("--------------------------------- ");
                switch (event_code)
                {
                case STClientCode.LED_Join:

                    game_app.setupLedPeer(this);

                    event_params.Add((byte)1, game_app.getCurGame());
                    OperationResponse led_connected_response = new OperationResponse((byte)STServerCode.LConnected, event_params)
                    {
                        ReturnCode   = (short)0,
                        DebugMessage = "server feedback"
                    };
                    this.fiber.Enqueue(() => SendOperationResponse(led_connected_response, new SendParameters()));
                    is_led = true;

                    break;

                case STClientCode.APP_Check_Id:


                    Dictionary <byte, Object> id_params = new Dictionary <byte, Object>();
                    id_params.Add((byte)1, game_app.getCurGame());

                    String get_id = (String)event_params[(byte)100];

                    if (game_app.led_ready)
                    {
                        id_params.Add((byte)2, game_app.checkAvailable());

                        bool valid_id = game_app.getValidId(ref get_id);
                        Log.Debug("id: " + valid_id + " - " + get_id);

                        id_params.Add((byte)3, valid_id ? 1 : 0);
                        id_params.Add((byte)100, get_id);

                        id_params.Add((byte)200, game_app.getIosVersion());
                        id_params.Add((byte)201, game_app.getAndroidVersion());

                        this.client_id = get_id;
                    }

                    OperationResponse id_response = new OperationResponse((byte)STServerCode.Id_And_Game_Info, id_params)
                    {
                        ReturnCode   = (short)0,
                        DebugMessage = "server feedback"
                    };
                    this.fiber.Enqueue(() => SendOperationResponse(id_response, new SendParameters()));


                    this.client_id = get_id;

                    break;

                case STClientCode.LED_SwitchGame:
                    int switch_to_game = (int)event_params[(byte)1];
                    game_app.switchGame(switch_to_game);

                    break;

                default:
                    //Log.Warn("Undefined event code= "+event_code.ToString());

                    if (game_app.checkLed())
                    {
                        game_app.handleMessage(this, event_code, event_params);
                    }
                    else
                    {           // if no led available, kick them off!
                        Dictionary <byte, Object> _params = new Dictionary <byte, Object>();
                        _params.Add((byte)1, game_app.getCurGame());
                        OperationResponse _response = new OperationResponse((byte)STServerCode.Id_And_Game_Info, _params)
                        {
                            ReturnCode   = (short)0,
                            DebugMessage = "server feedback"
                        };
                        this.fiber.Enqueue(() => SendOperationResponse(_response, new SendParameters()));
                    }
                    break;
                }
                break;
            }
        }
Example #56
0
        public override void Parse(UserClient user, byte moduleCode, byte operationCode, OperationRequest operationRequest, SendParameters sendParameters)
        {
            ServerItemVo currentServer = new ServerItemVo();

            currentServer.id     = 1;
            currentServer.title  = "天府情缘";
            currentServer.host   = "192.168.1.35:4531";
            currentServer.status = 2;


            S2CMessage msg = new S2CMessage((byte)moduleCode, (byte)operationCode);

            msg.Add(1, JsonMapper.ToJson(currentServer));

            OperationResponse response = new OperationResponse((byte)moduleCode, msg);

            user.SendOperationResponse(response, sendParameters);

            Global.Info("获取当前服务器列表");
        }
Example #57
0
        public override void OnHandlerMessage(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            byte operCode = request.OperationCode;

            switch (operCode)
            {
            case (byte)OperationCode.ForTeam:     // 组队申请:最多3人一个队伍,也可以两人
                OnBattleTeam(request, response, peer, sendParameters);
                break;

            case (byte)OperationCode.CancelTeam:     // 取消组队:从系统组队列表中移除当前的Peer
                MyGameApplication.MyInstance.RemovePeer(peer.m_strRoomID, peer);
                response.ReturnCode = (short)ReturnCode.Success;
                break;

            case (byte)OperationCode.SyncMove:
                SyncRoleMove(request, response, peer, sendParameters);
                break;

            case (byte)OperationCode.SyncMoveAnim:
                SyncRoleMoveAnim(request, response, peer, sendParameters);
                break;

            case (byte)OperationCode.SyncMoveDir:
                SyncRoleMoveDir(request, response, peer, sendParameters);
                break;
            }
        }
Example #58
0
        public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey);
            string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }";

            PlayerInfo info = JsonConvert.DeserializeObject <PlayerInfo>(playerInfoStr);

            PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey));

            var room = FindRoom(joinRequest.RoomID);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info));
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                                                     new Dictionary <byte, object> {
                    { (byte)CommonParameterKey.Success, false }
                });
                peer.SendOperationResponse(response, sendParameters);
            }
        }
Example #59
0
        /// <summary>
        /// 同步角色移动位置
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="peer"></param>
        /// <param name="sendParameters"></param>
        void SyncRoleMove(OperationRequest request, OperationResponse response, ClientPeer peer, SendParameters sendParameters)
        {
            Dictionary <byte, object> m_dic = request.Parameters;
            object value;

            // 客户端传递过来的参数信息:角色ID,坐标:X,Y,Z  Y轴旋转:_rY
            if (m_dic.TryGetValue((byte)ParameterCode.SyncInfo, out value))
            {
                string strValue = value.ToString();
                //Helper.Log("SyncRoleMove:" + strValue);
                string[] pStr1 = strValue.Split(',');
                if (pStr1.Length == 5)
                {
                    // 保存角色位置信息
                    float x = float.Parse(pStr1[1]);
                    float y = float.Parse(pStr1[2]);
                    float z = float.Parse(pStr1[3]);
                    peer.m_vCurPos.x = x;
                    peer.m_vCurPos.y = y;
                    peer.m_vCurPos.z = z;

                    string strRes = pStr1[0];
                    for (int i = 1; i < 5; ++i)
                    {
                        strRes += "," + pStr1[i];
                    }
                    m_dic.Clear();
                    m_dic.Add((byte)ParameterCode.SyncInfo, strRes);

                    if (null == peer.m_myTeam)
                    {
                        return;
                    }

                    List <ClientPeer> pTeam = peer.m_myTeam.m_pTeam;
                    if (pTeam == null)
                    {
                        return;
                    }

                    // 通知队伍中的其他Peer返回队伍角色信息给客户端
                    for (int k = 0; k < pTeam.Count; ++k)
                    {
                        ClientPeer curPeer = pTeam[k];

                        // 九宫格同步
                        bool bSync = Helper.IsSudoKu(peer.m_vCurPos, curPeer.m_vCurPos);

                        if (curPeer != peer && bSync)
                        {
                            EventData eventData = new EventData();
                            eventData.Parameters = m_dic;
                            // 返回操作码
                            eventData.Code = (byte)OperationCode.SyncMove;
                            curPeer.SendEvent(eventData, new SendParameters());
                            float dis = Vector3.Distance(peer.m_vCurPos, curPeer.m_vCurPos);
                            Helper.Log("角色1位置:" + peer.m_vCurPos.ToString() + "--角色2位置:" + curPeer.m_vCurPos.ToString() + "--:当前角色之间的距离:" + dis);
                            //Helper.Log(curPeer.m_curRole.Name + "--:同步:" + peer.m_curRole.Name + "-移动位置信息:" + strRes);
                        }
                    }
                }
            }
        }
    public void ProcessMessage(StarCollectorPeer sender, OperationRequest operationRequest, SendParameters sendParameters)
    {
        if (operationRequest.OperationCode == (byte)AckRequestType.MoveCommand)
        {
            // move command from player
            long  actorID = (long)operationRequest.Parameters[0];
            float velX    = (float)operationRequest.Parameters[1];
            float velY    = (float)operationRequest.Parameters[2];

            // find actor
            Player player = (listPlayer.Find(pl =>
            {
                return(pl.actorID == actorID);
            }));

            player.velocityX = velX;
            player.velocityY = velY;

            //List<Player> listOtherPlayer =
        }
    }