ItsMods

Full Version: Read Modern Warfare 2 console with a C# program? (AlterIWNet dedicated server)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,
I am currently coding a program which will keep my server running and also save certain server information. What I want to do, is have an external program run alongside the server, which reads each individual line in the console. In the program, I will set it up to search the console for certain functions. In this program, I will also implement a server upkeep function to automatically maintain the server. I.E: Issue warnings for certain words being said, kick spammers and hack advertisers.

This is being coded in Visual C# 2008. I have basic skills in C#, but I am fairly competent in gsc (modern warfare 2's coding language) and pawn (san andreas multiplayer).

This is for an AlterIWNet dedicated server, so the offsets may be different to the normal game. I want to save certain information in uniquely created text files, which I will sort out myself. I am just after the console read code, i already have the console write code.

thanks in advance

EDIT: This is the code I have used for the plugin, would this work? It does require mod co-operation to save all stats.
Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using aIW;

namespace Modern_Warfare_2_Server_Save_and_Load
{

    public class Modern_Warfare_2_Server_Save_and_Load : AdminPluginBase
    {
        private string statspath = Directory.GetCurrentDirectory() + "/mods/STALKER/playerstats/";
        private string tempstatspath = "";
        private string savestring = "";
        public override void OnFrame()
        {
            if (GetDvar("sv_saveplayer") != "")
            {
                savestring += (GetDvar("sv_savestats") + " = " + GetDvar("sv_savestats_value") + "\n");
                SetDvar("sv_savestats", "");
                SetDvar("sv_savestats_value", "");
            }
            else if ((GetDvar("sv_saveplayer") == "") && (savestring != "") && (GetDvar("sv_saveplayerguid") != ""))
            {
                File.AppendAllText(GetDvar("sv_saveplayerguid"), savestring);
                SetDvar("sv_saveplayerguid", "");
                savestring = "";
            }
        }
        
        public override EventEat OnSay(AdminClient client, string message)
        {
            if (message.StartsWith("!save"))
            {
                WaitForNextSaveSlot(client);
            }
            else if (message.StartsWith("!rules"))
            {
                iPrintLnTo(client, "^3SHOW SERVER RULES HERE");
            }
            else
            {
                foreach (AdminClient player in GetClients())
                {
                    RawSayTo(client, client.Name + ": " + message);
                }
            }
            return EventEat.EatGame;
        }

        public void OnPlayerConnect(AdminClient client)
        {
            WaitForNextLoadSlot(client);
        }

        public void OnPlayerDisconnect(AdminClient client)
        {
            WaitForNextSaveSlot(client);
        }

        public void WaitForNextSaveSlot(AdminClient client)
        {
            while (true)
            {
                if (GetDvar("sv_saveplayer") == "")
                {
                    SetDvar("sv_saveplayer", client.ToString());
                    iPrintLnTo(client, "^3Saving..");
                    continue;
                }
                Thread.Sleep(100);
            }
        }

        public void WaitForNextLoadSlot(AdminClient client)
        {
            while (true)
            {
                if (GetDvar("sv_loadplayer") == "")
                {
                    SetDvar("sv_loadplayer", client.ToString());
                    tempstatspath = statspath + GetDvar("my_guid");
                    if (!File.Exists(tempstatspath))
                        iPrintLnTo(client, "^3Welcome! You appear to be new here. Please say !rules for the server rules.");
                    else
                    {
                        SetDvar("sv_loadplayer", client.ToString());
                        iPrintLnTo(client, "^3Loading..");
                    }
                    tempstatspath = "";
                    continue;
                }
                Thread.Sleep(100);
            }
        }
    }
}