Exemplo n.º 1
0
 public void CallS2SMethod(NebulaCommon.ServerType serverType, string method, object[] arguments)
 {
     lock (fiberLock) {
         if (mFiber != null)
         {
             mFiber.Enqueue(() => {
                 try {
                     S2SInvokeMethodStart start = new S2SInvokeMethodStart {
                         arguments        = arguments,
                         method           = method,
                         sourceServerID   = GameApplication.ServerId.ToString(),
                         targetServerType = (byte)serverType
                     };
                     EventData evt = new EventData((byte)S2SEventCode.InvokeMethodStart, start);
                     if (application != null && application.MasterPeer != null)
                     {
                         application.MasterPeer.SendEvent(evt, new SendParameters());
                     }
                 } catch (Exception ex) {
                     log.Info("exception");
                     log.Info(ex.Message);
                     log.Info(ex.StackTrace);
                 }
             });
         }
     }
 }
Exemplo n.º 2
0
        public void Operation(NebulaCommon.ServerType serverType, byte code, Dictionary <byte, object> parameters, bool reliable = true)
        {
            var peer = FindPeer(serverType);

            if (peer != null)
            {
                logger.PushColor(ConsoleColor.Blue);
                logger.Log("send operation -> {0}", serverType);
                logger.Log("operation code: {0}", code);
                logger.Log("reliable: {0}", reliable);
                logger.Log("parameters -> ");
                if (parameters != null)
                {
                    logger.Log("{0}", parameters.toHash().ToStringBuilder().ToString());
                }
                else
                {
                    logger.Log("(none)");
                }

                logger.PopColor();
                peer.OpCustom(code, parameters, reliable);
            }
            else
            {
                logger.PushColor(ConsoleColor.Red);
                logger.Log("Peer not found for server type = {0}", serverType);
                logger.PopColor();
            }
        }
Exemplo n.º 3
0
        private PhotonPeer FindPeer(NebulaCommon.ServerType serverType)
        {
            var lst = m_Listeners.Find(listener => listener.serverInfo.type == serverType);

            if (lst != null)
            {
                return(lst.peer);
            }
            return(null);
        }
Exemplo n.º 4
0
    private void HandleInvokeMethodEnd(IEventData eventData, SendParameters sendParameters)
    {
        bool   success = (bool)eventData.Parameters[(byte)ServerToServerParameterCode.Success];
        object result  = eventData.Parameters[(byte)ServerToServerParameterCode.Result] as object;
        string method  = eventData.Parameters[(byte)ServerToServerParameterCode.Method] as string;

        NebulaCommon.ServerType serverType = (NebulaCommon.ServerType)(byte) eventData.Parameters[(byte)ServerToServerParameterCode.TargetServer];

        if (success)
        {
            log.InfoFormat("method {0} successfully called on server {1}", method, serverType);
            if (result != null)
            {
                log.InfoFormat("method {0} call result = {1}".Color(LogColor.orange), method, result.ToString());

                switch (method)
                {
                case "RequestGuildInfo":
                {
                    HandleRequestGuildInfo(result);
                }
                break;

                case "RequestIcon": {
                    HandleRequestIcon(result);
                }
                break;

                case "SendChatBroadcast": {
                    Hashtable hash = result as Hashtable;
                    if (hash != null)
                    {
                        RPCErrorCode code = (RPCErrorCode)hash.GetValue <int>((int)SPC.ReturnCode, (int)RPCErrorCode.UnknownError);
                        log.InfoFormat("send chat broadcast response: {0}", code);
                    }
                }
                break;

                case "PlanetObjectUnderAttackNotification": {
                    log.Info("PlanetObjectUnderAttackNotification(): end response...");
                }
                break;

                case "AddNebulaCredits": {
                    log.Info($"S2SMETHOD: {method} ended with code {result}");
                }
                break;
                }
            }
        }
        else
        {
            log.InfoFormat("fail call method {0} on server {1}", method, serverType);
        }
    }
Exemplo n.º 5
0
        protected override void OnEvent(IEventData eventData, SendParameters sendParameters)
        {
            try {
                switch ((S2SEventCode)eventData.Code)
                {
                default:
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Received unknown event code {0}", eventData.Code);
                    }
                    break;
                }

                case S2SEventCode.UpdateShipModel:
                {
                    HandleUpdateShipModelEvent(eventData);
                    break;
                }

                case S2SEventCode.UpdateCharacter:
                {
                    HandleUpdateCharacterEvent(eventData);
                    break;
                }

                case S2SEventCode.GETInventoryItemEnd:
                {
                    GETInventoryItemTransactionEnd end = new GETInventoryItemTransactionEnd(eventData);
                    switch ((TransactionSource)end.transactionSource)
                    {
                    case TransactionSource.Store:
                    {
                        application.Stores.inventoryGETPool.HandleTransaction(end);
                        log.Info("GET transaction handled");

                        break;
                    }

                    case TransactionSource.Bank:
                    {
                        application.Clients.HandleTransaction(end);
                        log.Info("bank add transaction returned....");
                        break;
                    }
                    }
                    break;
                }

                case S2SEventCode.GETInventoryItemsEnd:
                {
                    GETInventoryItemsTransactionEnd end = new GETInventoryItemsTransactionEnd(eventData);
                    switch ((TransactionSource)end.transactionSource)
                    {
                    case TransactionSource.Mail:
                    {
                        application.Mail.inventoryItemsGETPool.HandleTransaction(end);
                        log.Info("get transaction handled");
                        break;
                    }
                    }
                    break;
                }

                case S2SEventCode.PUTInventoryItemEnd:
                {
                    HandlePUTInventoryTransactionEnd(eventData, sendParameters);
                    break;
                }

                //called when from login inap store we put item to character mail
                case S2SEventCode.PUTMailTransactionStart: {
                    HandlePutMailTransactionStart(eventData, sendParameters);
                }
                break;

                case S2SEventCode.InvokeMethodStart:
                {
                    string   method           = (string)eventData.Parameters[(byte)ServerToServerParameterCode.Method];
                    object[] arguments        = eventData.Parameters[(byte)ServerToServerParameterCode.Arguments] as object[];
                    string   sourceServerID   = eventData.Parameters[(byte)ServerToServerParameterCode.SourceServer] as string;
                    byte     targetServetType = (byte)eventData.Parameters[(byte)ServerToServerParameterCode.TargetServer];

                    var mtd = mInvoker.GetType().GetMethod(method);

                    S2SInvokeMethodEnd end = new S2SInvokeMethodEnd {
                        method           = method,
                        sourceServerID   = sourceServerID,
                        targetServerType = targetServetType,
                    };
                    if (mtd != null)
                    {
                        object result = mtd.Invoke(mInvoker, arguments);
                        end.callSuccess = true;
                        end.result      = result;
                    }
                    else
                    {
                        end.callSuccess = false;
                        end.result      = null;
                    }

                    EventData retEvent = new EventData((byte)S2SEventCode.InvokeMethodEnd, end);
                    SendEvent(retEvent, new SendParameters());
                    break;
                }

                case S2SEventCode.InvokeMethodEnd: {
                    bool   success = (bool)eventData.Parameters[(byte)ServerToServerParameterCode.Success];
                    object result  = eventData.Parameters[(byte)ServerToServerParameterCode.Result] as object;
                    string method  = eventData.Parameters[(byte)ServerToServerParameterCode.Method] as string;
                    NebulaCommon.ServerType serverType = (NebulaCommon.ServerType)(byte) eventData.Parameters[(byte)ServerToServerParameterCode.TargetServer];
                    if (success)
                    {
                        log.InfoFormat("method {0} successfully called on server {1}", method, serverType);
                    }
                    else
                    {
                        log.InfoFormat("fail call method {0} on server {1}", method, serverType);
                    }
                }
                break;
                }
            }catch (Exception ex) {
                log.Error(ex);
            }
        }