//=============================================================================
// IPLogger (Version 0.3 beta) source code by 
// Gerald Lance Tindall aka. <NDP>BOZO
// Email Address: bozo@newdefinitionsofpain.com
// November 29, 2002
// CODE NOT FOR REUSE WITHOUT PRIOR PERMISSION OF AUTHOR
//=============================================================================

==========================
Overview 
==========================
This is designed to allow Unreal I servers to have an IP Logging and Banning Capabilities.

==========================
General Notes 
==========================
Special Thanks to <NDP>Scorpion aka. }TCP{Wolf for providing some working code and making my life easier...

Thanks to all my beta testers out there!!! Wolf, butters, a_lesser_talent, JonahHex, RuDe, CrAzY, Havok, A-ass-in, Ripit, Bubbles, Zeus, Dookie, Incoming, & Hellbent. Plus all the folks that got kicked by accident...

I have decided that the console checking capabilities will not be added any time in the near future to the IPLogger code. I have determined that Hackbuster 3.0 will serve to provide an extensive console checking capability that will well complement IPLogger well and I recommend that all server admins upgrade to the new version and run this concurrently with IPLogger.

I have also reviewed other console checking/ip logging utilities that are currently in the works: 
Specifically, kickban by a_lesser_talent (email: ggargett@attbi.com) and mcp by butters (email: effect_ed@hotmail.com). Both are excellent utilities. Interested parties may with to contact the authors directly for the code. 

kickban is a server side only tool that allows ip logging, banning, and remote administration. It is highly based on }TCP{Wolf's ServerDog code.

mcp is a dual server/client package that allows ip logging, banning, console checking, and remote administration. It is also highly based on }TCP{Wolf's ServerDog code.     

IPLogger is a dual server/client package that allows ip logging and banning. Currently, there are no remote admin capabilities built in to the tool but this seems to be its only major fault.

Of all of the tools, each has its own strengths and weaknesses, but I believe that the IPLogger method of implementation will turn out to produce a more robust tool in the long run. 

The authors and I have corresponded and spoke about combining our efforts on a single tool. Unfortunately it seems we are approaching the same problem with totally different methods. Thus it may be difficult to pursue this option.
 
I believe we may be able to reuse some of the server admin code that is based off of }TCP{Wolf's ServerDog code and has been implemented in these tools listed above. Although I have been looking at a completely different means of implementing this functionality...Time will tell.


==========================
Files Included
==========================
IPLoggerVer0.3beta.txt - Help File

IPLogger.int - System File - allows IPLogger Server settings to be adjusted under advanced settings

IPLogger.ini - System File - contains server IPLogger configuration settings and IP Ban/Allow lists

IPLogger.u - System File - IPLogger Server side executable 

IPL.u - System File - IPLogger Client side executable
==========================
Installation
==========================
Extract the IPLogger.u, IPL.u, IPLogger.int, and IPLogger.ini files to your Unreal\system directory.

Open up your Unreal.ini file located in the Unreal\system directory.

Find the ServerPackages lines.

After them add:
ServerPackages=IPL
ServerActors=IPLogger.IPLoggerServer
Save the file. 

NOTE: Delete any ServerPackages and ServerActors lines from previous installations of IPLogger.

IPLogger is now installed and will run automatically when the server is restarted.

===========================
Operation
===========================
The IPLogger program runs transparently in the background without input from the users. It collects Client IP address data, Computer Name, and Engine Version information and writes this data to the Unreal.log file.

A log entry will be made each time a new client joins the server and at the beginning of each new map change a full listing will be made of all current client machines.

A sample log section containing a log entry has been included below for your reference. Excerpt for Unreal.log:

ScriptLog: -- IPLoggerServer:LOG ENTRY --
ScriptLog: -- Name: <NDP>BOZO --
ScriptLog: -- PlayerNumber: 1 --
ScriptLog: -- IP: 192.168.0.1 --
ScriptLog: -- ComputerName: BOZOWORLD --
ScriptLog: -- EngineVersion: 225 --
ScriptLog: Ban[x]=<NDP>BOZO,192.168.0.1,BOZOWORLD,StandardLogEntry

Note that the last line is included after each log entry just to make it easier on you people when you want to add someone to the ban or allow lists. Basically just copy and paste this line to the end of your IPLogger.ini file - Add one to the previous Ban[x] line and enter that value at the [x] and save the file and they will be banned automatically at the next map change. You won't even have to restart the server....Start numbering with 0 please....I think it will work even if you screw up the numbering but I haven't tested that kinda stuff yet....Haven't made things very dummy proof at this time. 

The server can ban or allow client machines based on IP Address (single IP ban or range ban), PlayerName, or ComputerName. In addition, you are able to check for successful client communication. If there is no communication then you can ban based on this. Settings to ban/allow based on each criteria are set in the IPLogger.ini file. 

A sample section containing server configuration information has been included below for your reference. Excerpt from IPLogger.ini:

[IPLogger.IPLoggerServer]
ServerPort=8500
checktime=3.0
startchecktime=10
nocommbantime=10.0
Debug=0
bDisplayBanMessage=1
bCruelBan=0
BanJoiners=1
BanByPlayerName=1
BanByIPAddress=1
BanByComputerName=1
BanForNotCommunicating=1
AllowAccess=1
AllowByPlayerName
AllowByIPAddress
AllowByComputerName
Ban[0]={ABC}TEST,192.168.0.1,ABC001,LoserWhoWroteThisIPs
Ban[1]=<ABC>TEST2,192.168.0.1:192.168.255.255,ABC002,SomeMoreofTheLoserWhoWroteThisIPs
Allow[0]=<NDP>BOZO,,,MakersRights!!


[ServerPort] sets a particular port for use by the IPLoggerServer messaging. This was made adjustable in case of port conflicts at a server location.
IMPORTANT: THIS PORT MUST BE OPENED IN YOUR FIREWALL.

[checktime] sets how often the server will look for a new joiner. You should not set this too low or too high. 5 seconds would be about the minimum and 10 about the maximum I would set it at. 


[startchecktime] sets a delay to not begin logging after a map change/restart or server start. This is included because the server is usually really busy right then and I don't want to slow it down too much.
No issues have been noted with this setting.


[nocommbantime] sets a minimum time required for successful communication. 
{NDP}Bubbles has reported that for some slower connections the default nocommbantime seems to be too short. Doubling this value to 20.0 seemed to allow players to join that were previously being banned for not communicating. Thanks for the test help Bubbles!! 

[Debug] this is a boolean [0=no, 1=yes] whether to comment profusely to the log. Used for debugging. Turn this off if everything runs fine. It will really reduce the amount of log entries made and speed up the server.

[bDisplayBanMessage] this is a boolean [0=no, 1=yes] whether to display a message when a joining player has been banned in the standard message window. 

[bCruelBan] this is a boolean [0=no, 1=yes] whether to attempt a console lockup on the player being banned from the server and then kicking them. Otherwise just kicks them. NOT WORKING!!

[BanJoiners] this is a boolean [0=no, 1=yes] this enables/disables banning. Will override BanByPlayerName, BanByIPAddres, BanByComputerName, and BanForNotCommunicating settings if set to false.

[BanByPlayerName] this is a boolean [0=no, 1=yes] whether to check for a PlayerName match for ban.

[BanByIPAddress] this is a boolean [0=no, 1=yes] whether to check for a IPAddress match for ban.

[BanByComputerName] this is a boolean [0=no, 1=yes] whether to check for a ComputerName match for ban.

[BanForNotCommunicating] this is a boolean [0=no, 1=yes] whether to check for a no communication for ban. Slower servers seem to have problems with this being activated. Disable this check if you are having people drop for no communication...
 
[AllowAccess] this is a boolean [0=no, 1=yes] this enables/disables allowing access. Will override AllowByPlayerName, AllowByIPAddress, AllowByComputerName settings if set to false.

[AllowByPlayerName] this is a boolean [0=no, 1=yes] whether to check for a PlayerName match for allowing access.
[AllowByIPAddress] this is a boolean [0=no, 1=yes] whether to check for a IPAddress match for allowing access.
[AllowByComputerName] this is a boolean [0=no, 1=yes] whether to check for a ComputerName match for allowing access.


The following two lines contain ban information.

Ban[0]={ABC}TEST,192.168.0.1,ABC001,LoserWhoWroteThisIPs
Ban[1]=<ABC>TEST2,192.168.0.1:192.168.255.255,ABC002,SomeMoreofTheLoserWhoWroteThisIPs

It is in the following format:

Ban[x]=PlayerName,IPAddressorRange,ComputerName,DescriptionorReasonforBan

For each new line to be added add one to the value in the parenthesis [x]. Thus if we wanted to add a new line the next one would be x=2;Then include data in each of the Fields following the equals sign. DO NOT USE SPACES, COMMAS, OR COLONS EXCEPT AS SEPARATORS!!! Commas are used to separate the fields and colons are used to separate an IPAddress Range. Spaces will just be problematic. For your convienience I have included a dummy line following each log entry that can be copied over to make it easier to ban people.

The benefits of using this Ban list format is that each loser out there can get added to a ban list on one server and then all that is needed is the transfer of the IPLogger.ini file to another server. Thus ban lists can be updated easily throughout the Unreal world.

If you wish to just ban by a particular item and don't wish to enter data for the rest just enter nothing.

ex: to ban by IPAddress=192.168.1.1 enter

Ban[x]=,192.168.1.1,,

for your ban line.
Thanks to {hLk}HaVok for this configuration tip.

The last line contains allow information

Allow[0]=<NDP>BOZO,,,MakersRights!!

It is in the following format:

Allow[x]=PlayerName,IPAddressorRange,ComputerName,DescriptionorReasonforAllow

For each new line to be added add one to the value in the parenthesis [x]. Thus if we wanted to add a new line the next one would be x=2;Then include data in each of the Fields following the equals sign. DO NOT USE SPACES, COMMAS, OR COLONS EXCEPT AS SEPARATORS!!! Commas are used to separate the fields and colons are used to separate an IPAddress Range. Spaces will just be problematic. For your convienience I have included a dummy line following each log entry that can be copied over to make it easier to allow people.

Note that the allow list supercedes entries made to the ban list. Thus if the same PlayerName appears in both the allow and ban list that Player will be allowed into the server. The same goes for IPAddress or Computer Name entries.

If you wish to just allow by a particular item and don't wish to enter data for the rest just enter nothing.

ex: to allow by IPAddress=192.168.1.1 enter

Allow[x]=,192.168.1.1,,

for your allow line.
Thanks to {hLk}HaVok for this configuration tip.


==========================
Current Changes 
==========================
This is a major patch to fix server crash issues caused in the ban code. It also corrects the ver 224 incompatibility problems. Added functionality has also been added.

Thanks to all my beta testers out there!!! Wolf, butters, a_lesser_talent, JonahHex, RuDe, CrAzY, Havok, A-ass-in, Ripit, Bubbles, Zeus, Dookie, Incoming, & Hellbent. Plus all the folks that got kicked by accident....

1) I believe this version has corrected the server instability and restart problems that occured with version 0.2 beta. In addition, new functionality has been added. I have implemented a linked list structure to store IPLog data. The prior array structure was quickly overloaded on some busy servers. This new structure should allow unlimited (HA!) amounts of server join activity to be logged.

Special Thanks to {DvT}JonahHex and the GreatGreenHeron (GGH) server, the NDP clan, the T! clan, Dookie, {hLk}HaVok, =BAD=RuDe=> and =BAD=Crazy for running some test servers and bringing this problem to light.

2)I have also included a new IPLogger.int file - the prior file was an older version and did not work correctly when adjusting parameters from Advanced options. This fixes that bug.

3) Ver 224 incompatibility has been fixed. We found out that version 224 servers could not run IPLogger without an immediate crash occuring as soon as someone joined. Turns out that ver 224 does not support ROLE_AutonomousProxy correctly. Thus I had to do a complete rewrite to offer support for versions (224-226). This took me most of my time to fix....but it was worth it.

Special Thanks to ==BAD==RUDE, ==BAD=kRaZy=, and butters for running a test server and finding and helping troubleshoot this issue.

4) Logging Errors caused by the presence of Server controlled Pawns (Scripted Pawns) in the Levels created all kinds of issues. Changed Pawnlist walkthrough to Owner.PlayerReplicationInfo walkthrough. Fixed.

Special Thanks to <NDP>Scorpion aka. }TCP{Wolf for finding this one and suggesting a correction.

5) Logging Errors caused by people changing their PlayerNames quickly and by having invalid characters in their names was messing up the Logging. Fixed by changing to a Owner.PlayerPawn reference comparison. Also ran a filter on the PlayerName prior to checking and logging. Fixed.

Special Thanks to <NDP>Scorpion aka. }TCP{Wolf for finding this one and suggesting a correction.

6) I also am now destroying the IPLClient actor after data is logged from a player. This reduces network overhead. It didn't work correctly before but does now....Fixed.

7)In addition, new functionality has been added. 
7.1)An Allow list has been added. Can't recall who asked for this feature but thanks!!
7.2)Debug mode. Allows you to turn the verbose logging on and off.
7.3)Ban Notify Message can be turned on/off. It also appears in the normal message area now.
Thanks to Dookie and }TCP{Wolf for these suggestions.

8)For people who want to get access to the log data while the server is running this configuration is recommended. Thanks to <NDP>Zeus for figuring out the specifics and doing all of the testing!!

A batch file is all that is needed. Create a simple batch file called start.bat: 

:top 
ucc.exe server dmariza.unr log=server.log 
copy server.log server_crash.log 
goto top 


Run that script from a command prompt (not the run line) using the following:

start.bat >> logfile.txt 

With that all the standard output you would usually see in the Unreal console window is now redirected to the file logfile.txt. 
This output file is being run by a 16-bit batch file which cannot lock the txt file the way unreal locks it's log file. Thus you can access the log directly from the logfile.txt file while the unreal server is operating.

Thanks <NDP>Zeus for showing us the way!!

In addition, <NDP>Zeus has also been creating some outside utilities that allow you to quickly scan the log files for entries etc. We hope to start including these utilities with future versions of IPLogger.

9)Other known problems that were unrelated to my code but I troubleshot anyways: 

Specifically, we were having problems running DMInjector.unr correctly. At first we thought the problem was caused by my new code. I looked deep into the problem and decided that it was caused by the UnrealI package not loading at runtime. Turns out that DMInjector does not reference any object in the UnrealI package. Thus you could run it just fine with just the Unreal Shareware distribution. The fix is to add the following line to your ServerPackages list:

ServerPackages=UnrealI

Special Thanks to ==BAD==RUDE and ==BAD=kRaZy= for running a test server and finding this ultra wacky DMInjector issue.

===========================
Known Bugs
===========================
The Cruel Ban routine is not currently operating the way I want it to. Thus it is considered a bug. Thanks to butters for the idea.

When operating as a Non-dedicated Listen server IPLogger will crash. Thanks to <NDP>Bubbles for this bug report. Still not fixed. Quick workaround: just run it dedicated and rejoin from a second Unreal instance run on the same machine. It will work then...
===========================
Future Plans
===========================
Fix the Cruel Ban. Thanks to butters for the idea! Working my way through this one...not sure if I can make it work though...

Fix the Listen server crash problem. Haven't even started looking into this one yet...

Implement some error checking of the IPLogger.ini settings. Follow the directions people!!

Disable the ver 226 Server Rejoin bind thingy. 

Currently it takes about 10 seconds to ban someone new joining. I will try to speed this up a bit. I plan on checking the PlayerName at PreLogin. Nothing else can be checked at this point that I can see so far.... Also I am going to add a ban option for someone entering with the default name of Player.

Admin Exec commands to add people to the ban list dynamically, allow remote admining of servers. Note to =BAD=RuDe> and a_lesser_talent and others requesting this it is coming sometime in the future. I think I have figured out how to do this without using the "admin set a a blah" thingy from ServerDog also... 

Need to test for successful operation with all various Unreal Mods: Serpentine, Infiltration, RealCTF, RTNP, Coop, MonsterMash, etc....Had to get ver 224 compatibility working first...Will add mod specific code where necessary to support these games on future versions. Haven't tested any of this stuff yet so it may work (or it may not). Give me feedback please!


===========================
Contact Me!!
===========================
Please help make this a better program!
Email me any problems you find or suggested features at bozo@newdefinitionsofpain.com

Thanks!!  


===========================
Disclaimer
===========================
This is intended solely to help in the administering of Unreal servers - not to collect data about client machines for other nefarious purposes. 

  