Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Read Modern Warfare 2 console with a C# program? (AlterIWNet dedicated server)
#1
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);
            }
        }
    }
}
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Windows 8.1 Fix for MW3 Server Addon master131 16 18,202 09-29-2014, 23:08
Last Post: SuperNovaAO
Brick [Release] MW3 Server Administration Addon iRoNinja 5 9,015 11-10-2013, 15:46
Last Post: Casper
  [Release] Bot Warfare ineedbots 0 4,882 11-10-2013, 06:15
Last Post: ineedbots
Exclamation Help cmdlist, dvarlist server crash Nerus 17 11,920 11-09-2013, 23:54
Last Post: Nerus
  Our Level Fastfile is Different from the Server. CheeseToast 6 11,327 11-03-2013, 17:52
Last Post: CheeseToast
  Dedicated Server External (public) IP Nerus 3 5,903 11-02-2013, 14:16
Last Post: Casper
  MW3 Server Version superg1973 7 12,756 10-28-2013, 01:15
Last Post: kotyra972
  Help how to turn off map in dedicated server pero123 8 7,146 10-15-2013, 19:00
Last Post: Nekochan
  Issue with server addon and NAT dimitrifrom31 3 5,086 10-08-2013, 18:11
Last Post: iRoNinja
  Help MW3 (External) Console - TeknoMW3? Strazeeh 7 8,711 10-01-2013, 21:54
Last Post: DeHEnergY

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.