Exemplo n.º 1
0
 public override void OnActivate(NebulaObject source, out RPCErrorCode errorCode)
 {
     errorCode = RPCErrorCode.Ok;
     if (interactable)
     {
         if (pirates.Count == 0)
         {
             if (existsPlayersInWorld)
             {
                 for (int i = 0; i < mPirateCount; i++)
                 {
                     var obj = GeneratePirate();
                     //(nebulaObject.world as MmoWorld).AddObject(obj);
                     obj.AddToWorld();
                     pirates.Add(obj);
                 }
                 InteractOff();
                 log.InfoFormat("pirate activator started".Yellow());
             }
             else
             {
                 errorCode = RPCErrorCode.NoPlayersAtZone;
             }
         }
         else
         {
             errorCode = RPCErrorCode.CollectionNotEmpty;
         }
     }
     else
     {
         errorCode = RPCErrorCode.ObjectNotInteractable;
     }
 }
Exemplo n.º 2
0
		private static string FindMessage(RPCErrorCode code)
		{
			switch(code)
			{
				case RPCErrorCode.RPC_MISC_ERROR:
					return "std::exception thrown in command handling";
				case RPCErrorCode.RPC_FORBIDDEN_BY_SAFE_MODE:
					return "Server is in safe mode, and command is not allowed in safe mode";
				case RPCErrorCode.RPC_TYPE_ERROR:
					return "Unexpected type was passed as parameter";
				case RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY:
					return "Invalid address or key";
				case RPCErrorCode.RPC_OUT_OF_MEMORY:
					return "Ran out of memory during operation";
				case RPCErrorCode.RPC_INVALID_PARAMETER:
					return "Invalid, missing or duplicate parameter";
				case RPCErrorCode.RPC_DATABASE_ERROR:
					return "Database error";
				case RPCErrorCode.RPC_DESERIALIZATION_ERROR:
					return "Error parsing or validating structure in raw format";
				case RPCErrorCode.RPC_TRANSACTION_ERROR:
					return "General error during transaction submission";
				case RPCErrorCode.RPC_TRANSACTION_REJECTED:
					return "Transaction was rejected by network rules";
				case RPCErrorCode.RPC_TRANSACTION_ALREADY_IN_CHAIN:
					return "Transaction already in chain";
				default:
					return code.ToString();
			}
		}
Exemplo n.º 3
0
		public RPCException(RPCErrorCode code, string message, RPCResponse result)
			: base(String.IsNullOrEmpty(message) ? FindMessage(code) : message)
		{
			_RPCCode = code;
			_RPCCodeMessage = FindMessage(code);
			_RPCResult = result;
		}
Exemplo n.º 4
0
 public RPCException(RPCErrorCode code, string message, RPCResponse result)
     : base(String.IsNullOrEmpty(message) ? FindMessage(code) : message)
 {
     _RPCCode        = code;
     _RPCCodeMessage = FindMessage(code);
     _RPCResult      = result;
 }
Exemplo n.º 5
0
        public bool RequestToGuild(string login, string characterID, string guildID)
        {
            RPCErrorCode code    = RPCErrorCode.Ok;
            bool         success = application.Guilds.RequestToGuild(login, characterID, guildID, out code);

            return(success);
        }
Exemplo n.º 6
0
    private void HandleRequestIcon(object result)
    {
        Hashtable hash = result as Hashtable;

        if (hash != null)
        {
            RPCErrorCode code = (RPCErrorCode)hash.GetValue <int>((int)SPC.ReturnCode, (int)RPCErrorCode.UnknownError);

            if (code == RPCErrorCode.Ok)
            {
                string gameRef = hash.GetValue <string>((int)SPC.GameRefId, string.Empty);
                int    icon    = hash.GetValue <int>((int)SPC.Icon, 0);
                if (!string.IsNullOrEmpty(gameRef))
                {
                    MmoActor player;
                    if (m_App.serverActors.TryGetValue(gameRef, out player))
                    {
                        if (player)
                        {
                            var character = player.GetComponent <PlayerCharacterObject>();
                            if (character)
                            {
                                character.SetIcon(icon);
                            }
                        }
                    }
                }
            }
            else
            {
                log.InfoFormat("RPC:RequestIcon error: {0}", code);
            }
        }
    }
Exemplo n.º 7
0
 private static JObject CreateError(RPCErrorCode code, string message)
 {
     JObject response = new JObject();
     response.Add("result", null);
     JObject error = new JObject();
     response.Add("error", error);
     error.Add("code", (int)code);
     error.Add("message", message);
     return response;
 }
Exemplo n.º 8
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.º 9
0
        private OperationResponse ErrorResponse(OperationRequest request, int rpcId, RPCErrorCode code)
        {
            RPCInvokeResponse respInstance = new RPCInvokeResponse {
                rpcId  = rpcId,
                result = new Hashtable {
                    { (int)SPC.ReturnCode, (int)code }
                }
            };

            return(new OperationResponse(request.OperationCode, respInstance));
        }
Exemplo n.º 10
0
        static JObject CreateError(RPCErrorCode code, string message)
        {
            var response = new JObject();

            response.Add("result", null);
            var error = new JObject();

            response.Add("error", error);
            error.Add("code", (int)code);
            error.Add("message", message);
            return(response);
        }
Exemplo n.º 11
0
        public static RPCException BuildException(RPCErrorCode code, string message, object response)
        {
            var jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                }
            };

            var rawMessage = JsonConvert.SerializeObject(response, jsonSerializerSettings);

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(rawMessage)))
            {
                return(new RPCException(code, message, RPCResponse.Load(stream)));
            };
        }
Exemplo n.º 12
0
        public void ReceiveCode(RPCErrorCode code)
        {
            var eventInstance = new ItemGeneric {
                ItemId          = nebulaObject.Id,
                ItemType        = nebulaObject.Type,
                CustomEventCode = (byte)CustomEventCode.ReceiveErrorCode,
                EventData       = new Hashtable {
                    { (int)SPC.ReturnCode, (int)code }
                }
            };
            SendParameters sendParameters = new SendParameters {
                Unreliable = false,
                ChannelId  = Settings.ItemEventChannel
            };
            EventData eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);

            ReceiveEvent(eventData, sendParameters);
        }
Exemplo n.º 13
0
        private OperationResponse CallUserEvent(MmoActor player, OperationRequest request, RPCInvokeOperation op)
        {
            if (op.parameters != null && op.parameters.Length > 0)
            {
                RPCErrorCode  code      = RPCErrorCode.Ok;
                UserEventName eventName = (UserEventName)(int)op.parameters[0];
                switch (eventName)
                {
                case UserEventName.object_scanner_select_ship:
                case UserEventName.start_moving:
                case UserEventName.rotate_camera: {
                    //if (player.GetComponent<QuestManager>().TryCheckActiveQuests(new UserEvent(eventName))) {
                    //    s_Log.InfoFormat("player complete some quest with event: {0}".Lime(), eventName);
                    //} else {
                    //    s_Log.InfoFormat("no quest completed by event: {0}".Orange(), eventName);
                    //}
                }
                break;

                case UserEventName.dialog_completed: {
                    //if(op.parameters.Length > 1) {
                    //    string dialogId = (string)op.parameters[1];
                    //    player.GetComponent<DialogManager>().CompleteDialog(dialogId);
                    //} else {
                    //    code = RPCErrorCode.MissedParameter;
                    //}
                }
                break;

                default: {
                    s_Log.Info(string.Format("error: no support for event: {0}", eventName).Red());
                    code = RPCErrorCode.UnsupportedEvent;
                }
                break;
                }

                RPCInvokeResponse respInstance = new RPCInvokeResponse {
                    rpcId  = op.rpcId,
                    result = (int)code
                };
                return(new OperationResponse(request.OperationCode, respInstance));
            }
            return(InvalidOperationParameter(request));
        }
Exemplo n.º 14
0
        private static string FindMessage(RPCErrorCode code)
        {
            switch (code)
            {
            case RPCErrorCode.RPC_MISC_ERROR:
                return("std::exception thrown in command handling");

            case RPCErrorCode.RPC_FORBIDDEN_BY_SAFE_MODE:
                return("Server is in safe mode, and command is not allowed in safe mode");

            case RPCErrorCode.RPC_TYPE_ERROR:
                return("Unexpected type was passed as parameter");

            case RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY:
                return("Invalid address or key");

            case RPCErrorCode.RPC_OUT_OF_MEMORY:
                return("Ran out of memory during operation");

            case RPCErrorCode.RPC_INVALID_PARAMETER:
                return("Invalid, missing or duplicate parameter");

            case RPCErrorCode.RPC_DATABASE_ERROR:
                return("Database error");

            case RPCErrorCode.RPC_DESERIALIZATION_ERROR:
                return("Error parsing or validating structure in raw format");

            case RPCErrorCode.RPC_TRANSACTION_ERROR:
                return("General error during transaction submission");

            case RPCErrorCode.RPC_TRANSACTION_REJECTED:
                return("Transaction was rejected by network rules");

            case RPCErrorCode.RPC_TRANSACTION_ALREADY_IN_CHAIN:
                return("Transaction already in chain");

            default:
                return(code.ToString());
            }
        }
Exemplo n.º 15
0
        public override void OnActivate(NebulaObject source, out RPCErrorCode errorCode)
        {
            errorCode = RPCErrorCode.Ok;

            /*
             *
             * if(interactable) {
             *  if(IsDistanceValid(source)) {
             *      var questMgr = source.GetComponent<QuestManager>();
             *
             *      if(questMgr != null ) {
             *          switch (activatorType) {
             *              case ActivatorType.BoolVarSet: {
             *                      questMgr.SetBoolVariable(variableName, (bool)m_ActivatorValue);
             *                  }
             *                  break;
             *              case ActivatorType.FloatVarSet: {
             *                      questMgr.SetFloatVariable(variableName, (float)m_ActivatorValue);
             *                  }
             *                  break;
             *              case ActivatorType.IntVarIncr: {
             *                      questMgr.IncreaseInteger(variableName, (int)m_ActivatorValue);
             *                  }
             *                  break;
             *              case ActivatorType.IntVarSet: {
             *                      questMgr.SetIntegerVariable(variableName, (int)m_ActivatorValue);
             *                  }
             *                  break;
             *          }
             *      }
             *      InteractOff();
             *  } else {
             *      errorCode = RPCErrorCode.DistanceIsFar;
             *  }
             * } else {
             *  errorCode = RPCErrorCode.ObjectNotInteractable;
             * }*/
        }
Exemplo n.º 16
0
 public RPCError(RPCErrorCode error, string message)
     : this(error, message, null)
 {
 }
Exemplo n.º 17
0
 /// <summary>
 /// Activate action this activator
 /// </summary>
 /// <param name="source">What object is activator source</param>
 /// <param name="errorCode">Error code or Ok</param>
 /// <returns>Status</returns>
 public abstract void OnActivate(NebulaObject source, out RPCErrorCode errorCode);
Exemplo n.º 18
0
 protected Hashtable CreateResponse(RPCErrorCode code)
 {
     return(new Hashtable {
         { (int)SPC.ReturnCode, (int)code }
     });
 }
Exemplo n.º 19
0
 public RPCError(RPCErrorCode error)
     : this(error, error.ToString())
 {
 }
Exemplo n.º 20
0
 public RPCServerException(RPCErrorCode errorCode, string message) : base(message)
 {
     this.ErrorCode = errorCode;
 }
Exemplo n.º 21
0
        public bool RequestToGuild(string login, string characterID, string guildID, out RPCErrorCode code)
        {
            var player = mApplication.Players.GetExistingPlayerByLogin(login);

            if (player == null)
            {
                log.InfoFormat("RequestToGuild: player with login = {0} not exists [green]", login);
                code = RPCErrorCode.PlayerNotFound;
                return(false);
            }
            var character = player.Data.GetCharacter(characterID);

            if (character == null)
            {
                log.InfoFormat("RequestToGuild: player with character = {0} not exists [green]", characterID);
                code = RPCErrorCode.CharacterNotFound;
                return(false);
            }

            if (character.HasGuild())
            {
                log.InfoFormat("RequestToGuild: character already in guild [green]");
                code = RPCErrorCode.CharacterAlreadyInGuild;
                return(false);
            }

            Guild guild = GetGuild(guildID);

            if (guild == null)
            {
                log.InfoFormat("RequestToGuild: guild = {0} don't exists [green]");
                code = RPCErrorCode.CoalitionNotFound;
                return(false);
            }

            if (guild.closed)
            {
                log.InfoFormat("RequestToGuild: guild is closed");
                code = RPCErrorCode.CoalitionInClosedState;
                return(false);
            }

            //string text = string.Format("Player {0} want join to you guild. Allow this action?", login);
            Hashtable notificationData = new Hashtable {
                { (int)SPC.Action, (int)GuildAction.RequestToGuild },
                { (int)SPC.Guild, guildID },
                { (int)SPC.CharacterId, characterID },
                { (int)SPC.Login, login }
            };

            string uniqueID = login + characterID + guildID + NotificationSourceServiceType.Guild.ToString() + NotificationSubType.RequestToGuild.ToString();

            foreach (var member in guild.GetPrivilegedUsers())
            {
                var notification = mApplication.Notifications.Create(uniqueID, "s_note_request_guild", notificationData, NotficationRespondAction.YesDelete,
                                                                     NotificationSourceServiceType.Guild, NotificationSubType.RequestToGuild);
                mApplication.Notifications.SetNotificationToCharacter(member.characterId, notification);
                log.InfoFormat("Guild request sended to = {0} [green]", member.login);
            }
            code = RPCErrorCode.Ok;
            return(true);
        }
Exemplo n.º 22
0
        public bool BuyStoreItem(string login, string gameRef, string character, int race, int inworkshop, int level, string productType, string server, out RPCErrorCode errorCode)
        {
            errorCode = RPCErrorCode.Ok;

            if (level < application.serverSettings.pvpStoreMinLevel)
            {
                log.InfoFormat("player level very low for pvp store {0}:{1} [red]", level, application.serverSettings.pvpStoreMinLevel);
                errorCode = RPCErrorCode.LevelNotEnough;
                return(false);
            }

            var storeItem = application.pvpStoreItems.GetItem(productType.ToLower());

            if (storeItem == null)
            {
                log.InfoFormat("pvp store item {0} not founded [red]", productType.ToLower());
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            var store = application.Stores.GetOnlyPlayerStore(character);

            if (store == null)
            {
                log.InfoFormat("player store not founded [red]");
                errorCode = RPCErrorCode.ObjectNotFound;
                return(false);
            }

            if (store.pvpPoints < storeItem.price)
            {
                log.InfoFormat("player don't enough pvp points for purchase {0}:{1}", store.pvpPoints, storeItem.price);
                errorCode = RPCErrorCode.DontEnoughPvpPoints;
                return(false);
            }

            int workshop = inworkshop;

            if (Rand.Float01() >= 0.9f)
            {
                workshop = (byte)CommonUtils.RandomWorkshop((Race)(byte)race);
            }

            IInfo result = null;

            if (storeItem.isWeapon)
            {
                WeaponDropper dropper = new WeaponDropper(new WeaponDropper.WeaponDropParams(application.resource, level, (Workshop)(byte)workshop, WeaponDamageType.damage, Difficulty.none), 1f);
                result = (dropper.DropWeapon() as IInfo);
            }
            else
            {
                switch (productType.ToLower())
                {
                case "es":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.ES);
                }
                break;

                case "cb":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CB);
                }
                break;

                case "cm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.CM);
                }
                break;

                case "dm":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DM);
                }
                break;

                case "df":
                {
                    result = CreateModule(workshop, level, ShipModelSlotType.DF);
                }
                break;
                }
            }

            if (result == null)
            {
                log.InfoFormat("creating item error [red]");
                errorCode = RPCErrorCode.UnknownError;
                return(false);
            }

            var itemHash = result.GetInfo();

            PUTInventoryItemTransactionStart start = new PUTInventoryItemTransactionStart {
                characterID           = character,
                count                 = 1,
                gameRefID             = gameRef,
                itemID                = itemHash.GetValue <string>((int)SPC.Id, string.Empty),
                postTransactionAction = (byte)PostTransactionAction.RemovePvpPoints,
                inventoryType         = (byte)InventoryType.ship,
                tag                    = storeItem.price,
                targetObject           = itemHash,
                transactionID          = Guid.NewGuid().ToString(),
                transactionSource      = (byte)TransactionSource.PvpStore,
                transactionEndServer   = server,
                transactionStartServer = SelectCharacterApplication.ServerId.ToString()
            };
            EventData eventData = new EventData((byte)S2SEventCode.PUTInventoryItemStart, start);

            mPutTransactionPool.StartTransaction(start);
            application.MasterPeer.SendEvent(eventData, new SendParameters());
            log.InfoFormat("pass put transaction started [red]...");
            return(true);
        }
Exemplo n.º 23
0
 public RPCError(RPCErrorCode error, JToken data)
     : this(error, error.ToString(), data)
 {
 }
Exemplo n.º 24
0
 public RPCError(RPCErrorCode error, string message)
     : this(error, message, null)
 {
 }
Exemplo n.º 25
0
 public RPCError(RPCErrorCode error, string message, JToken data)
     : base(message)
 {
     this.Code = error;
       this.Data = data;
 }
Exemplo n.º 26
0
 public RPCError(RPCErrorCode error)
     : this(error, error.ToString())
 {
 }
Exemplo n.º 27
0
 public RPCError(RPCErrorCode error, string message, JToken data)
     : base(message)
 {
     this.Code = error;
     this.Data = data;
 }
Exemplo n.º 28
0
 public RPCError(RPCErrorCode error, JToken data)
     : this(error, error.ToString(), data)
 {
 }