Example #1
0
        private bool CheckLegacyToken()
        {
            string directory     = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\LyokoAPP";
            string fileDirectory = directory + @"\UserToken.txt";

            if (Directory.Exists(directory) && File.Exists(fileDirectory))
            {
                try
                {
                    string newDirectory     = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\ReplikAPP";
                    string newFileDirectory = newDirectory + @"\UserToken.txt";

                    Directory.CreateDirectory(newDirectory);
                    File.Move(fileDirectory, newFileDirectory);
                    Directory.Delete(directory, true);
                    LyokoLogger.Log(Name, "The token was successfully ported over from the LyokoAPP folder!");
                    return(true);
                }
                catch (Exception e)
                {
                    LyokoLogger.Log(Name, $"Something went wrong moving the token from LyokoAPP to ReplikAPP's folder. Please remove the LyokoAPP folder manually.': {e.ToString()}, check if you have write access to the directory");
                }
            }

            return(false);
        }
        public static async Task BridgeConnection()
        {
            //Checking Connection
            if (_client != null)
            {
                return;
            }

            //Finding Bridge
            IBridgeLocator locator = new HttpBridgeLocator();
            IEnumerable <LocatedBridge> bridgeIPs = await locator.LocateBridgesAsync(TimeSpan.FromSeconds(10));

            var locatedBridges = bridgeIPs.ToList();

            if (!locatedBridges.Any())
            {
                LyokoLogger.Log("CodeHue", "No bridges found!");
                Connected = false;
                return;
            }
            else
            {
                LyokoLogger.Log("CodeHue", "Bridge located.");
            }

            //Checking Application Registering
            _client = new LocalHueClient(locatedBridges.First().IpAddress);
            var appKeyPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                          "appKey.txt");

            if (System.IO.File.Exists(appKeyPath))
            {
                appKey = System.IO.File.ReadAllText(appKeyPath);
            }

            if (appKey.Length == 0)
            {
                LyokoLogger.Log("CodeHue", "Please press your Bridge's link button.");
                Timer myTimer = new Timer();
                myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
                myTimer.Interval = 5000;
                myTimer.Start();
                while (appKey.Length == 0)
                {
                }
                myTimer.Stop();
                System.IO.File.WriteAllText(appKeyPath, appKey);
                LyokoLogger.Log("CodeHue", "Key registered.");
            }

            //Connecting To Bridge
            _client.Initialize(appKey);
            var command = new LightCommand();

            command.Alert = Alert.Once;
            await _client.SendCommandAsync(command);

            LyokoLogger.Log("CodeHue", "Successfully connected to the Bridge.");
            Connected = true;
        }
Example #3
0
        private static void sendEvent(string type, string json)
        {
            LyokoLogger.Log("POST", json);
            //string s = Encoding.ASCII.GetString(client.UploadData(Globals.domain + "/"+type, "POST", Encoding.Default.GetBytes(json)));
            WebRequest request = WebRequest.Create(Globals.domain + type);

            request.Method = "POST";
            string postData = json;

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/json";
            request.ContentLength = byteArray.Length;


            //Here is the Business end of the code...
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            //and here is the response.
            WebResponse response = request.GetResponse();

            LyokoLogger.Log("GOT", ((HttpWebResponse)response).StatusDescription);
            dataStream = response.GetResponseStream();
            StreamReader reader             = new StreamReader(dataStream);
            string       responseFromServer = reader.ReadToEnd();

            //Console.WriteLine(responseFromServer);
            reader.Close();
            dataStream.Close();
            response.Close();
            LyokoLogger.Log("GOT", responseFromServer);
        }
Example #4
0
 public override void OnGameStart(bool storyMode)
 {
     if (storyMode)
     {
         LyokoLogger.Log(Name, "Storymode started. TenSuperscan is disabled. The plugin will be re-enabled once you return to the menu.");
         Disable();
     }
     LyokoLogger.Log(Name, "Game start event detected.");
 }
 public static async void DisplayTimeEvent(object source, ElapsedEventArgs e)
 {
     try
     {
         appKey = await _client.RegisterAsync("CodeHue_Test2", "Computer");
     }
     catch (Exception exc)
     {
         LyokoLogger.Log("CodeHue", "Button not pressed. Trying again...");
     }
 }
Example #6
0
        private bool ReadToken()
        {
            if (!CheckLegacyToken())
            {
                string directory     = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\ReplikAPP";
                string fileDirectory = directory + @"\UserToken.txt";
                if (Directory.Exists(directory) && File.Exists(fileDirectory))
                {
                    try
                    {
                        string token = File.ReadAllText(fileDirectory, Encoding.UTF8);
                        if (token.Length > 0)
                        {
                            _token = token;
                            LyokoLogger.Log(Name, "User token successfully loaded!");
                            return(true);
                        }

                        LyokoLogger.Log(Name, @"Please input the token given by ReplikAPP in \ReplikAPP\UserToken.txt");
                        LyokoLogger.Log(Name, "The plugin will disable now, restart the game once the token is in the file.");
                        return(false);
                    }
                    catch (Exception e)
                    {
                        LyokoLogger.Log(Name,
                                        "Something went wrong when reading the token! Please check that only your token is inside UserToken.txt");
                        return(false);
                    }
                }

                try
                {
                    Directory.CreateDirectory(directory);
                    File.Create(fileDirectory);
                }
                catch (Exception e)
                {
                    LyokoLogger.Log(Name,
                                    $"Something went wrong creating the config directory: {e.ToString()}, check if you have write access to the directory");
                    return(false);
                }

                LyokoLogger.Log(Name,
                                @"Please input the token given by ReplikAPP in UserToken.txt (in ReplikAPP's folder)");
                LyokoLogger.Log(Name, "The plugin will disable now, restart the game once the token is in the file.");
                return(false);
            }
            return(true);
        }
Example #7
0
        protected override void DoCommand(string[] args)
        {
            Output("args:" + args[0]);
            LyokoWarrior warrior = null;

            try
            {
                warrior = LyokoWarriors.GetByName(args[0].ToLower());
            }
            catch (Exception e)
            {
                LyokoLogger.Log(Name, e.ToString());
            }
            if (warrior == null)
            {
                Output("no warrior");
                throw new CommandException(this, "invalid warrior!");
            }
            Output("warrior: " + warrior.WarriorName);
            LW_VirtEvent.Call(warrior, "forest");
            Output(warrior.WarriorName + " virtualized.");
        }
Example #8
0
        private void OnCommand(string commandstring)
        {
            string[] commandargs = commandstring.Split(".");
            var      commandname = commandargs[0];

            if (commandargs.Length < 2)
            {
                commandargs = new string[] {};
            }
            else
            {
                commandargs = commandargs.ToList().GetRange(1, commandargs.Length).ToArray();
            }

            var command = Commands.FirstOrDefault(commandd => commandd.Name == commandname);

            command?.Run(commandargs);
            if (command == null)
            {
                LyokoLogger.Log(commandstring, "Command not recognized!");
            }
        }
Example #9
0
        public Listener(ICollection <Command> commands, int port)
        {
            Commands = new List <Command>(commands);

            /*ServicePointManager.ServerCertificateValidationCallback +=
             *  (sender, certificate, chain, sslPolicyErrors) => true;*/
            connection = new HubConnectionBuilder().WithUrl($"http://localhost:{port}/MiniLyokoHub").Build();

            StartConnection();
            connection.Closed += async(error) =>
            {
                await Task.Delay(new Random().Next(0, 5) * 1000);

                await connection.StartAsync();
            };

            TowerActivationEvent.Subscribe(OnTowerActivation);
            TowerDeactivationEvent.Subscribe(OnTowerDeactivation);
            TowerHijackEvent.Subscribe(OnTowerHijack);
            CommandOutputEvent.Subscribe(OnCommandOutput);
            LyokoLogger.Subscribe(OnLogger);
            CommandInputEvent.Subscribe(OnCommand);
        }
Example #10
0
        public static void Main(string[] args)
        {
            Console.Clear();
            var consoleLogger = LyokoLogger.Subscribe(msg => Console.WriteLine(msg));
            //DebugListener.Initialize();
            PluginLoader pluginLoader = new PluginLoader("Plugins");
            bool         isInList     = false;

            foreach (var plugin in pluginLoader.Plugins)
            {
                if (plugin.Name.Contains("logger"))
                {
                    isInList = true;
                }
            }
            if (isInList)
            {
                LyokoLogger.Unsubscribe(consoleLogger);
            }
            Console.ReadKey();
            ShowMenu();
            pluginLoader.DisableAll();
        }
Example #11
0
        public bool Disable()
        {
            try
            {
                bool succeeded = OnDisable();
                if (!succeeded)
                {
                    LyokoLogger.Log("LyokoAPIPlugin", $"{ToString()} Didn't disable sucessfully");
                    Enabled = true;
                }
                else
                {
                    LyokoLogger.Log("LyokoAPIPlugin", $"{ToString()} Was disabled sucessfully");
                    Enabled = false;
                }
            }
            catch (Exception e)
            {
                LyokoLogger.Log("LyokoAPIPlugin", $"{ToString()} threw an exception while disabling: {e.GetType()} {e.StackTrace}");
            }


            return(Enabled);
        }
Example #12
0
        private void createLocalizationDictionary()
        {
            try
            {
                string langCode     = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
                var    assembly     = Assembly.GetExecutingAssembly();
                string resourceName = "ReplikAPP_Plugin.Localization.ReplikAPP_Plugin_" + langCode.ToUpperInvariant() + ".json";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string result = reader.ReadToEnd();
                        Dictionary <string, object> dictionary = JsonParser.ParseJSON(result);
                        foreach (string key in dictionary.Keys)
                        {
                            localization.Add(cleanString(key), cleanString((string)dictionary[key], true));
                        }
                    }
            }
            catch (Exception e)
            {
                LyokoLogger.Log("ReplikAPP", e.ToString());
            }
        }
Example #13
0
 public override void OnInterfaceEnter()
 {
     LyokoLogger.Log(Name, "you entered the interface");
 }
Example #14
0
 protected override bool OnEnable()
 {
     LyokoLogger.Log("CodeHue", "Launching CodeHue...");
     SetUp();
     return(true);
 }
 private static void OnTowerDeactive(ITower tower)
 {
     LyokoLogger.Log(Name, String.Format("<{2}> Activated tower has been deactivated in the {0} region. ({0} - {1})", tower.Sector.Name.ToUpper(), tower.Number, tower.Sector.World.Name.ToUpper()));
 }
Example #16
0
 private static void DoAThing()
 {
     LyokoLogger.Log("ExamplePlugin", "I did a thing!");
 }
 private static void OnTowerHijack(ITower tower, APIActivator oldA, APIActivator newA)
 {
     LyokoLogger.Log(Name, String.Format("<{4}> A tower in the {0} region has been hijacked by {1} ({0} #{2}: {3}->{1})", tower.Sector.Name.ToUpper(), newA.ToString().ToUpper(), tower.Number, oldA.ToString().ToUpper(), tower.Sector.World.Name.ToUpper()));
 }
 private static void OnXANAWake()
 {
     LyokoLogger.Log(Name, "It would seem XANA raises his ugly head once more.");
 }
 private static void onXANASleep()
 {
     LyokoLogger.Log(Name, "RETURN TO THE PAST NOW!!!! (XANA has been defeated)");
 }
Example #20
0
 public override void OnGameEnd(bool failed)
 {
     Enable();
     LyokoLogger.Log(Name, "Game end event detected.");
 }
Example #21
0
 public static void Log(string message)
 {
     LyokoLogger.Log("TenSuperscan", message);
 }
Example #22
0
 public override void OnInterfaceExit()
 {
     LyokoLogger.Log(Name, "you stepped away from the interface");
 }
 private static void OnTowerActive(ITower tower)
 {
     LyokoLogger.Log(Name, String.Format("<{3}> Active tower by {0} detected in the {1} region. ({1} - {2})", tower.Activator.ToString().ToUpper(), tower.Sector.Name.ToUpper(), tower.Number, tower.Sector.World.Name.ToUpper()));
 }