Ejemplo n.º 1
0
 /// <summary>
 /// Asynchronously log into the server -- meaning, this function returns immediately
 /// while it attempts to login to the server. When it finishes, it calls the
 /// 'callback' function handed in.
 /// </summary>
 /// <param name="user">Username to login with.</param>
 /// <param name="password">Password for the user.</param>
 /// <param name="version">Version of the client.</param>
 /// <param name="callback">Callback, called when the login finishes.</param>
 /// <exception cref="Network.Exceptions.UnknownException">
 /// Thrown if any error occurs. It's unusual.</exception>
 public void LoginAsync(string user, string password, VTankObject.Version version,
                        ActionFinished callback)
 {
     try
     {
         remoteCallback = callback;
         factory.VTankLogin_async(new Login_Callback(LoginCallback),
                                  user, password, version);
     }
     // Unknown exceptions are escalated because it's unusual for an error to happen here.
     catch (Ice.Exception e)
     {
         logger.Error("LoginAsync() Ice.Exception: {0}", e);
         throw new UnknownException("Unable to establish a connection for logging in.");
     }
     catch (NullReferenceException e)
     {
         logger.Error("LoginAsync() System.NullReferenceException: {0}", e);
         throw new UnknownException("Unable to establish a connection for logging in.");
     }
     catch (System.Exception e)
     {
         logger.Error("LoginAsync() System.Exception: {0}", e);
         throw new UnknownException("Unable to establish a connection for logging in.");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Update an existing tank with new information asynchronously. This method may throw an
        /// exception if the information is invalid, or if an unknown error occurs.
        /// </summary>
        /// <param name="name">Name of the tank.</param>
        /// <param name="speedFactor">Speed factor of the tank.</param>
        /// <param name="armorFactor">Armor factor of the tank.</param>
        /// <param name="model">Model name of the tank.</param>
        /// <param name="weaponId">Weapon ID used with the tank.</param>
        /// <param name="color">Color of the tank.</param>
        /// <param name="callback">Method to be called once it finishes.</param>
        public void UpdateTankAsync(string name, float speedFactor, float armorFactor, string model, string skin,
                                    int weaponId, VTankObject.VTankColor color, ActionFinished <bool> callback)
        {
            VTankObject.TankAttributes tank = new VTankObject.TankAttributes(
                name, speedFactor, armorFactor, 0, 100, model, skin,
                weaponId,
                color);

            CheckTank(tank);

            try
            {
                session.UpdateTank_async(new UpdateTank_Callback(callback), name, tank);
            }
            catch (Ice.Exception e)
            {
                logger.Error("UpdateTankAsync() Unexpected Ice.Exception: {0}", e);
                throw new UnknownException("Connection lost: An unknown error occurred.");
            }
            catch (System.Exception e)
            {
                logger.Error("UpdateTankAsync() Unexpected System.Exception: {0}", e);
                throw new UnknownException("An unknown error occurred.");
            }

            // Assume the best.
            tankListNeedsRefresh = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete a tank that you own asynchronously. Note that if you send an invalid name or
        /// a name that is not in the list, it will throw an exception.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="callback"></param>
        public void DeleteTankAsync(string name, ActionFinished <bool> callback)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new InvalidValueException("The tank name must not be empty.");
            }

            // Check if the tank exists in the cached list.
            RefreshTankList();

            bool exists = false;

            for (int i = 0; i < tankList.Length; i++)
            {
                if (tankList[i].name == name)
                {
                    exists = true;

                    break;
                }
            }

            if (!exists)
            {
                throw new InvalidValueException("That tank does not exist.");
            }

            session.DeleteTank_async(new DeleteTank_Callback(callback), name);

            // Assume the best.
            tankListNeedsRefresh = true;
        }
Ejemplo n.º 4
0
        private static void MoveClick(object sender, EventArgs e)
        {
            var p = Game.Instance.ActivePlayer;

            p.Character.EditCharProperty(CharacterAttribute.CurrentEnergy, EditCharPropertyChangeType.Subtract, 1);
            p.CurrentLocation = ((LocationSelectionButton)sender).LocationNumber;
            _MainForm.Instance.LocationCardsPanel.AddMissingMapTiles();
            DisableMoveMode();
            ActionFinished.Invoke();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// This method acts as the callback for the timer. When called, if KeepAlive is
 /// enabled and Connected is true, this method attempts to call KeepAlive on
 /// the main server.
 /// </summary>
 /// <param name="o">Unused.</param>
 private void OnKeepAlive(object o)
 {
     if (KeepAlive && Connected)
     {
         lock (this)
         {
             ActionFinished <NoReturnValue> callback = CommonExceptionHandler <NoReturnValue>;
             session.KeepAlive_async(new KeepAlive_Callback(callback));
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the user's list of tanks asynchronously. It won't attempt to get a new list
        /// if it already has it cached and it doesn't need to be refreshed.
        /// </summary>
        /// <param name="finishedCallback">Function to call when the tank list returns.</param>
        /// <returns>True if the tank list does not need refreshing, and it is already
        /// available.</returns>
        public bool GetTankListAsync(ActionFinished <VTankObject.TankAttributes[]> finishedCallback)
        {
            if (!tankListNeedsRefresh)
            {
                return(true);
            }

            session.GetTankList_async(new GetTankList_Callback(finishedCallback));

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Intercepts the login attempt in order to provide some internal handling.
        /// </summary>
        /// <param name="result">Result of the login attempt.</param>
        /// <param name="session">Session proxy, if one exists.</param>
        /// <param name="e">Exception thrown from the callback.</param>
        private void LoginCallback(Result <MainSessionPrx> result)
        {
            System.Exception e = result.Exception;
            if (result.Success)
            {
                if (KeepAlive)
                {
                    keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive),
                                               null, KeepAliveInterval, KeepAliveInterval);
                }

                session = result.ReturnedResult;
                session.GetTankList();

                //session = MainSessionPrxHelper.uncheckedCast(session.ice_router(router));
                pinger = new Pinger(session);
            }
            else
            {
                logger.Error("LoginCallback() Login attempt failed: {0}", e);
                if (e is PermissionDeniedException)
                {
                    PermissionDeniedException ex = (PermissionDeniedException)e;
                    e = new LoginFailedException(ex.reason);
                }
                else
                {
                    e = new LoginFailedException("Unable to login.");
                }

                result.Exception = e;
            }

            remoteCallback(new Result(result.Success, session, result.Exception));
            remoteCallback = null;
        }
Ejemplo n.º 8
0
 public DeleteTank_Callback(ActionFinished <bool> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 9
0
 public GetRank_Callback(ActionFinished <int> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 10
0
 public Fire_Callback(ActionFinished<NoReturnValue> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 11
0
 public DeleteTank_Callback(ActionFinished<bool> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 12
0
 public KeepAlive_Callback(ActionFinished<NoReturnValue> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 13
0
 public GetRank_Callback(ActionFinished<int> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 14
0
 internal void on_ActionFinished(Pawn ControlledPawn, byte WithResult) =>
 ActionFinished?.Invoke(ControlledPawn, WithResult);
Ejemplo n.º 15
0
 static void PassClick(object sender, EventArgs e)
 {
     Game.Instance.PlayerPassed();
     ActionFinished.Invoke();
 }
Ejemplo n.º 16
0
 static void ExplorationActionClick(object sender, EventArgs e)
 {
     ExplorationManager.StartExploration(Game.Instance.ActivePlayer.CurrentLocation);
     ActionFinished.Invoke();
 }
Ejemplo n.º 17
0
 static void LocationActionClick(object sender, EventArgs e)
 {
     CombatManager.Start();
     ActionFinished.Invoke();
 }
Ejemplo n.º 18
0
 public DownloadMap_Callback(ActionFinished <VTankObject.Map> _callback)
 {
     callback = _callback;
 }
        public override async Task <NodeActionFinishedArgs> InvokeNodeFunction(NodeActionTriggerTypes actionType, string[] otherData, string altFunction = "")
        {
            if (!(bool)IsActivated)
            {
                return(await Task.FromResult(new NodeActionFinishedArgs()
                {
                    result = "NOT_ACTIVATED", data = $"MQTT Publish Node - {Name} - Node is not activated. You cannot invoke action!"
                }));
            }

            if (actionType != ActualTriggerType)
            {
                return(await Task.FromResult(new NodeActionFinishedArgs()
                {
                    result = "NOT_INVOKED", data = $"MQTT Publish Node - {Name} - Node is not set to this {Enum.GetName(actionType)} of trigger. It is set to {Enum.GetName(ActualTriggerType)}!"
                }));
            }

            JSResultDto jsRes = new JSResultDto();

            // Node Custom JavaScript call
            if (ParsedParams.IsScriptActive)
            {
                if (!string.IsNullOrEmpty(ParsedParams.Script) && (otherData.Length > 0))
                {
                    if (!string.IsNullOrEmpty(altFunction))
                    {
                        jsRes = JSScriptHelper.RunNodeJsScript(altFunction, ParsedParams.ScriptParametersList, otherData);
                    }

                    jsRes = JSScriptHelper.RunNodeJsScript(ParsedParams.Script, ParsedParams.ScriptParametersList, otherData);

                    if (!jsRes.done)
                    {
                        return(await Task.FromResult(new NodeActionFinishedArgs()
                        {
                            result = "NOT_INVOKED", data = $"MQTT Publish Node - {Name} - Custom JS script runned with error {jsRes.payload}!"
                        }));
                    }
                }
            }

            try
            {
                var p = JsonConvert.DeserializeObject <MQTTNodeParams>(ParsedParams.Parameters);

                if (p != null)
                {
                    if (string.IsNullOrEmpty(p.Topic))
                    {
                        return(await Task.FromResult(new NodeActionFinishedArgs()
                        {
                            result = "NOT_INVOKED", data = $"MQTT Publish Node - {Name} - Topic is not set!"
                        }));
                    }

                    if (ParsedParams.TimeDelay > 0)
                    {
                        await Task.Delay(ParsedParams.TimeDelay);
                    }

                    var res = string.Empty;

                    if (ParsedParams.Command != null)
                    {
                        var payload = string.Empty;

                        if (ParsedParams.IsScriptActive && !string.IsNullOrEmpty(jsRes.payload))
                        {
                            payload = jsRes.payload;
                        }
                        else
                        {
                            payload = p.Data;
                        }

                        LastPayload   = payload;
                        LastOtherData = otherData;

                        NodeActionRequestTypes type = NodeActionRequestTypes.MQTTPublishNotRetain;

                        if (p.Retain)
                        {
                            type = NodeActionRequestTypes.MQTTPublishRetain;
                        }

                        ActionRequest?.Invoke(this, new NodeActionRequestArgs()
                        {
                            Type    = type,
                            Topic   = p.Topic,
                            Payload = payload
                        });
                    }
                    else
                    {
                        res = $"MQTT Publish Node - {Name} - Command cannot be null. Please fill full Topic name!";
                        log.Warn($"Node {Name} MQTT Publish Node - Command cannot be null. Please fill full Topic name!!");
                    }

                    ActionFinished?.Invoke(this, new NodeActionFinishedArgs()
                    {
                        result = "OK", data = res
                    });

                    return(await Task.FromResult(new NodeActionFinishedArgs()
                    {
                        result = "OK", data = res
                    }));
                }
                else
                {
                    log.Warn($"Node {Name} cannot send MQTT Publish. Cannot parse the parameters!");
                    return(await Task.FromResult(new NodeActionFinishedArgs()
                    {
                        result = "ERROR", data = $"MQTT Publish Node - {Name} - Cannot parse the parameters!"
                    }));
                }
            }
            catch (Exception ex)
            {
                log.Error($"Node {Name} cannot send MQTT Publish. ", ex);
            }

            return(await Task.FromResult(new NodeActionFinishedArgs()
            {
                result = "ERROR", data = "Unexpected error!"
            }));
        }
Ejemplo n.º 20
0
 public void setCallback(ActionFinished s)
 {
     actionFinished = s;
 }
Ejemplo n.º 21
0
 public DownloadMap_Callback(ActionFinished<VTankObject.Map> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Asynchronously gets the rank of a player's tank.
 /// </summary>
 /// <param name="callback"></param>
 public void GetRankAsync(ActionFinished <int> callback)
 {
     session.GetRank_async(new GetRank_Callback(callback));
 }
Ejemplo n.º 23
0
 public GetTankList_Callback(ActionFinished<VTankObject.TankAttributes[]> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 24
0
 public GameKeepAlive_Callback(ActionFinished <NoReturnValue> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 25
0
 public Login_Callback(ActionFinished<MainSessionPrx> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 26
0
 public Login_Callback(ActionFinished <MainSessionPrx> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 27
0
 public virtual void Finish()
 {
     FinishTime = null;
     ActionFinished?.Invoke(this, this);
 }
Ejemplo n.º 28
0
        public override async Task <NodeActionFinishedArgs> InvokeNodeFunction(NodeActionTriggerTypes actionType, string[] otherData, string altFunction = "")
        {
            if (!(bool)IsActivated)
            {
                return(await Task.FromResult(new NodeActionFinishedArgs()
                {
                    result = "NOT_ACTIVATED", data = "HTTP API Node - Node is not activated. You cannot invoke action!"
                }));
            }

            if (actionType != ActualTriggerType)
            {
                return(await Task.FromResult(new NodeActionFinishedArgs()
                {
                    result = "NOT_INVOKED", data = $"HTTP API Node - Node is not set to this {Enum.GetName(actionType)} of trigger. It is set to {Enum.GetName(ActualTriggerType)}!"
                }));
            }

            JSResultDto jsRes = new JSResultDto();

            // Node Custom JavaScript call
            if (ParsedParams.IsScriptActive)
            {
                if (!string.IsNullOrEmpty(ParsedParams.Script) && (otherData.Length > 0))
                {
                    if (!string.IsNullOrEmpty(altFunction))
                    {
                        jsRes = JSScriptHelper.RunNodeJsScript(altFunction, ParsedParams.ScriptParametersList, otherData);
                    }

                    jsRes = JSScriptHelper.RunNodeJsScript(ParsedParams.Script, ParsedParams.ScriptParametersList, otherData);

                    if (!jsRes.done)
                    {
                        return(await Task.FromResult(new NodeActionFinishedArgs()
                        {
                            result = "NOT_INVOKED", data = $"HTTP API Node - Custom JS script runned with error {jsRes.payload}!"
                        }));
                    }
                }
            }

            try
            {
                var p = JsonConvert.DeserializeObject <HTTPApiRequestNodeParams>(ParsedParams.Parameters);

                if (p != null)
                {
                    var url = string.Empty;
                    if (!p.UseHttps)
                    {
                        url = $"http://{p.Host}";
                    }
                    else
                    {
                        url = $"https://{p.Host}";
                    }

                    if (!string.IsNullOrEmpty(p.Port))
                    {
                        url += $":{p.Port}/";
                    }
                    else
                    {
                        url += "/";
                    }

                    if (!string.IsNullOrEmpty(p.ApiCommand))
                    {
                        url += p.ApiCommand;
                    }

                    if (ParsedParams.TimeDelay > 0)
                    {
                        await Task.Delay(ParsedParams.TimeDelay);
                    }

                    var payload = string.Empty;
                    if (ParsedParams.IsScriptActive && !string.IsNullOrEmpty(jsRes.payload))
                    {
                        payload = jsRes.payload;
                    }
                    else
                    {
                        payload = p.Data;
                    }

                    LastPayload   = payload;
                    LastOtherData = otherData;

                    var res = string.Empty;

                    if (ParsedParams.Command != null)
                    {
                        switch (ParsedParams.Command)
                        {
                        case "GET":
                            res = await SendGETRequest(url, payload);

                            break;

                        case "PUT":
                            res = await SendPURequest(url, payload);

                            break;

                        case "":
                            res = "HTTP API Node - Command cannot be empty. Please fill GET, POST or PUT!";
                            log.Warn($"Node {Name} cannot send HTTP Request. Command is empty. Please fill GET, POST or PUT!");
                            break;
                        }
                    }
                    else
                    {
                        res = "HTTP API Node - Command cannot be null. Please fill GET, POST or PUT!";
                        log.Warn($"Node {Name} cannot send HTTP Request. Command is null. Please fill GET, POST or PUT!");
                    }

                    ActionFinished?.Invoke(this, new NodeActionFinishedArgs()
                    {
                        result = "OK", data = res
                    });

                    return(await Task.FromResult(new NodeActionFinishedArgs()
                    {
                        result = "OK", data = res
                    }));
                }
                else
                {
                    return(await Task.FromResult(new NodeActionFinishedArgs()
                    {
                        result = "ERROR", data = "HTTP API Node - Cannot parse the parameters!"
                    }));

                    log.Warn($"Node {Name} cannot send HTTP Request. Cannot parse the parameters!");
                }
            }
            catch (Exception ex)
            {
                log.Error($"Node {Name} cannot send HTTP Request. ", ex);
            }

            return(await Task.FromResult(new NodeActionFinishedArgs()
            {
                result = "ERROR", data = "Unexpected error!"
            }));
        }
Ejemplo n.º 29
0
 public Move_Callback(ActionFinished <NoReturnValue> _callback)
 {
     callback = _callback;
 }
Ejemplo n.º 30
0
 public GetTankList_Callback(ActionFinished <VTankObject.TankAttributes[]> _callback)
 {
     callback = _callback;
 }