Beispiel #1
0
 void springProcess_Exited(object sender, EventArgs e)
 {
   process = null;
   talker.Close();
   talker = null;
   if (SpringExited != null) SpringExited(this, EventArgs.Empty);
 }
Beispiel #2
0
    void talker_SpringEvent(object sender, Talker.SpringEventArgs e)
    {
      switch (e.EventType) {
        case Talker.SpringEventType.PLAYER_JOINED:
          if (PlayerJoined != null) PlayerJoined(this, new SpringLogEventArgs(e.PlayerName));
          break;

        case Talker.SpringEventType.PLAYER_LEFT:
          if (e.Param == 0) if (PlayerDisconnected != null) PlayerDisconnected(this, new SpringLogEventArgs(e.PlayerName));
            else if (PlayerLeft != null) PlayerLeft(this, new SpringLogEventArgs(e.PlayerName));
          break;

        case Talker.SpringEventType.PLAYER_CHAT:
          if (PlayerSaid != null) PlayerSaid(this, new SpringLogEventArgs(e.PlayerName, e.Text));
          break;

        case Talker.SpringEventType.PLAYER_DEFEATED:
          if (PlayerLost != null) PlayerLost(this, new SpringLogEventArgs(e.PlayerName));
          break;

        case Talker.SpringEventType.SERVER_GAMEOVER:
//          if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName));
          break;
        
        case Talker.SpringEventType.SERVER_QUIT:
          if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName));
          break;

      }

    }
Beispiel #3
0
    // SPRING.EXE functions
    public void StartGame(Battle battle)
    {
      if (!IsRunning) {

        ConfigMaker.Generate(path + "springie.txt", battle, out players);

        process = new Process();
        process.StartInfo.CreateNoWindow = true;

        if (Program.main.config.SpringStartsMinimized) {
          process.StartInfo.Arguments = "/minimise ";
        } else process.StartInfo.Arguments = "";
        process.StartInfo.Arguments += "springie.txt";

        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.WorkingDirectory = path;
        process.StartInfo.FileName = path + ExecutableName;
        process.StartInfo.UseShellExecute = false;
        process.Exited += new EventHandler(springProcess_Exited);
        
        Thread.Sleep(1000); // give time to user's spring to start and ignore upcoming registry hax
        PrepareRegistry();
        process.Start();

        gameStarted = DateTime.Now;
        process.WaitForInputIdle();

        outputReader = new Thread(SpringOutputReader);
        outputReader.Name = "SpringOutputReader";
        outputReader.Start(this);
        talker = new Talker(process);

        RestoreRegistry();
        if (IsRunning && SpringStarted != null) SpringStarted(this, EventArgs.Empty);
        
        SpringWindowHidden = Program.main.config.SpringStartsHidden;
        System.Threading.Thread.Sleep(1000);
        ProcessPriority = Program.main.config.HostingProcessPriority;
      }
    }
Beispiel #4
0
    // SPRING.EXE functions
    public void StartGame(Battle battle)
    {
      if (!IsRunning) {

        List<Battle.GrPlayer> players;
        talker = new Talker();
        talker.SpringEvent += new EventHandler<Talker.SpringEventArgs>(talker_SpringEvent);
        string configName = "springie" + Program.main.AutoHost.config.HostingPort + ".txt";
        ConfigMaker.Generate(path + configName, battle, talker.LoopbackPort, out players);
        talker.SetPlayers(players);


        process = new Process();
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.Arguments += configName;
        process.StartInfo.WorkingDirectory = path;
        process.StartInfo.FileName = path + ExecutableName;
        process.StartInfo.UseShellExecute = false;
        process.Exited += new EventHandler(springProcess_Exited);
        
        process.Start();
        process.ProcessorAffinity = (IntPtr)Program.main.config.SpringCoreAffinity;

        gameStarted = DateTime.Now;
        process.WaitForInputIdle();

    
        if (IsRunning && SpringStarted != null) SpringStarted(this, EventArgs.Empty);
        
        System.Threading.Thread.Sleep(1000);
        ProcessPriority = Program.main.config.HostingProcessPriority;
      }
    }
Beispiel #5
0
        private void talker_SpringEvent(object sender, Talker.SpringEventArgs e)
        {
            switch (e.EventType) {
                case Talker.SpringEventType.PLAYER_JOINED:
                    //Program.main.AutoHost.SayBattle("dbg joined " + e.PlayerName);
                    if (PlayerJoined != null) PlayerJoined(this, new SpringLogEventArgs(e.PlayerName));
                    break;

                case Talker.SpringEventType.PLAYER_LEFT:
                    //Program.main.AutoHost.SayBattle("dbg left " + e.PlayerName);
                    if (e.Param == 0 && PlayerDisconnected != null) PlayerDisconnected(this, new SpringLogEventArgs(e.PlayerName));
                    if (PlayerLeft != null) PlayerLeft(this, new SpringLogEventArgs(e.PlayerName));

                    break;

                case Talker.SpringEventType.PLAYER_CHAT:

                    HandlePlanetWarsMessages(e);

                    // only public chat
                    if (PlayerSaid != null && (e.Param == Talker.TO_EVERYONE || e.Param==Talker.TO_EVERYONE_LEGACY)) PlayerSaid(this, new SpringLogEventArgs(e.PlayerName, e.Text));
                    break;

                case Talker.SpringEventType.PLAYER_DEFEATED:
                    //Program.main.AutoHost.SayBattle("dbg defeated " + e.PlayerName);
                    if (PlayerLost != null) PlayerLost(this, new SpringLogEventArgs(e.PlayerName));
                    break;

                case Talker.SpringEventType.SERVER_GAMEOVER:
                    //Program.main.AutoHost.SayBattle("dbg gameover " + e.PlayerName);
                    if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName));
                    break;

                case Talker.SpringEventType.PLAYER_READY:
                    //Program.main.AutoHost.SayBattle("dbg ready " + e.PlayerName);
                    if (e.Param == 1) readyPlayers.Add(e.PlayerName);
                    break;

                case Talker.SpringEventType.SERVER_QUIT:
                    //Program.main.AutoHost.SayBattle("dbg quit ");
                    //if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName));
                    break;
            }
        }
Beispiel #6
0
        private void HandlePlanetWarsMessages(Talker.SpringEventArgs e)
        {
            if (!Program.main.config.PlanetWarsEnabled || Program.main.PlanetWars == null) return;
            if (e.Param >= Talker.TO_EVERYONE_LEGACY) return;

            int count;
            if (!PlanetWarsMessages.TryGetValue(e.Text, out count)) count = 0;
            count++;
            PlanetWarsMessages[e.Text] = count;
            if (count != 2) return; // only send if count matches 2 exactly

            if (Program.main.PlanetWars != null) Program.main.PlanetWars.SpringMessage(e.Text);
        }
Beispiel #7
0
        public void StartGame(Battle battle)
        {
            if (!IsRunning) {
                List<Battle.GrPlayer> players;
                talker = new Talker();
                readyPlayers.Clear();
                talker.SpringEvent += talker_SpringEvent;
                string configName = Path.Combine(Program.WorkPath, "springie" + Program.main.AutoHost.config.HostingPort + ".txt").Replace('\\', '/');
                ConfigMaker.Generate(configName, battle, talker.LoopbackPort, out players);
                talker.SetPlayers(players);


                process = new Process();
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.Arguments += configName;
                process.StartInfo.FileName = Program.main.config.ExecutableName;
                process.StartInfo.WorkingDirectory = Path.GetDirectoryName(Program.main.config.ExecutableName);
                process.StartInfo.UseShellExecute = false;
                process.Exited += springProcess_Exited;
                process.EnableRaisingEvents = true;
                PlanetWarsMessages = new Dictionary<string, int>();
                process.Start();
                gameStarted = DateTime.Now;
                Thread.Sleep(1000);
                if (!Program.IsLinux && IsRunning) process.PriorityClass = Program.main.config.HostingProcessPriority;
                if (IsRunning && SpringStarted != null) SpringStarted(this, EventArgs.Empty);
            }
        }
Beispiel #8
0
    // SPRING.EXE functions
    public void StartGame(TasClient.Battle battle)
    {
      if (!IsRunning) {
        joinedPlayers = new List<string>();
        lostPlayers = new List<string>();

        ConfigMaker.Generate(path + "springie.txt", battle);
        PrepareRegistry();
        process = new Process();
        process.StartInfo.CreateNoWindow = true;

        if (Program.main.config.SpringStartsHidden) {
          process.StartInfo.Arguments = "/minimise ";
        } else process.StartInfo.Arguments = "";
        process.StartInfo.Arguments += "springie.txt";
        
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.WorkingDirectory = path;
        process.StartInfo.FileName = path + ExecutableName;
        process.StartInfo.UseShellExecute = false;
        process.Start();

        gameStarted = DateTime.Now;
        process.Exited += new EventHandler(springProcess_Exited);
        process.WaitForInputIdle();

        SpringWindowHidden = Program.main.config.SpringStartsHidden;
        Thread.Sleep(1000);

        RestoreRegistry();

        outputReader = new Thread(SpringOutputReader);
        outputReader.Name = "SpringOutputReader";
        outputReader.Start(this);

        talker = new Talker(process);

        if (!process.HasExited && SpringStarted != null) SpringStarted(this, new EventArgs());

        ProcessPriority = Program.main.config.HostingProcessPriority;
      }
    }