Ok, I apologize for letting these submissions sit here unfixed for a couple of weeks, but the good news is, I've had some time this week to make some necessary adjustments.
I basically completely reworked the way I was looking at IP banning - this way happens earlier and before the connection is added to the CLE, so it should be better for performance, etc (plus it actually works, where the other one didn't).
Here's the run-down:
- Added Rule: World:UseBannedIPsTable (default value: false (feature disabled))
- Added #Command: #ipban (default status 200).
- Syntax: #ipban [ip address]
- When #ipban adds an IP into the Banned_IPs table, it also adds the GM's name to the "notes" section.
Let me know what you think.
Required SQL:
Code:
CREATE TABLE `banned_ips` (
`ip_address` varchar(32) NOT NULL,
`notes` varchar(32) default NULL,
PRIMARY KEY (`ip_address`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
insert into rule_values values (0, 'World:UseBannedIPsTable', 'true');
insert into commands values ('ipban', 200);
This diff was taken against 0.7.0-1106
Code:
diff C:/1106/zone/command.h C:/vztz/zone/command.h
231a232
> void command_ipban(Client *c, const Seperator *sep);
diff C:/1106/zone/command.cpp C:/vztz/zone/command.cpp
362a363
> command_add("ipban","[IP Address] - Ban IP by character name",200,command_ipban) ||
1366a1368
> t->CastToClient()->cheat_timer.Start(3500,false); //Lieka: Prevent Zone-to-Zone GM Summons from triggering the MQZone and MQWarp detectors.
1412c1414
< if (sep->IsNumber(2) || sep->IsNumber(3) || sep->IsNumber(4))
---
> if (sep->IsNumber(2) || sep->IsNumber(3) || sep->IsNumber(4)) {
1413a1416
> c->CastToClient()->cheat_timer.Start(3500,false); //Lieka: Not sure why we put this here... should be an admin if you are zoning to special coordinates by this point.
1414a1418
> }
5149a5154,5168
>
> void command_ipban(Client *c, const Seperator *sep)
> {
> if(sep->arg[1] == 0)
> {
> c->Message(0, "Usage: #ipban [xxx.xxx.xxx.xxx]");
> } else {
> if(database.AddBannedIP(sep->arg[1], c->GetName())) {
> c->Message(0, "%s has been successfully added to the Banned_IPs table by %s",sep->arg[1], c->GetName());
> } else {
> c->Message(0, "IPBan Failed (IP address is possibly already in the table?)");
> }
> }
> }
>
diff C:/1106/world/net.cpp C:/vztz/world/net.cpp
361,364c361,378
< _log(WORLD__CLIENT, "New client from %s:%d", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
< Client* client = new Client(eqsi);
< // @merth: client->zoneattempt=0;
< client_list.Add(client);
---
> if (RuleB(World, UseBannedIPsTable)){ //Lieka: Check to see if we have the responsibility for blocking IPs.
> _log(WORLD__CLIENT, "Checking inbound connection %s against BannedIPs table", inet_ntoa(in));
> if (!database.CheckBannedIPs(inet_ntoa(in))){ //Lieka: Check inbound IP against banned IP table.
> _log(WORLD__CLIENT, "Connection %s PASSED banned IPs check. Processing connection.", inet_ntoa(in));
> Client* client = new Client(eqsi);
> // @merth: client->zoneattempt=0;
> client_list.Add(client);
> } else {
> _log(WORLD__CLIENT, "Connection from %s FAILED banned IPs check. Closing connection.", inet_ntoa(in));
> eqsi->Close(); //Lieka: If the inbound IP is on the banned table, close the EQStream.
> }
> }
> if (!RuleB(World, UseBannedIPsTable)){
> _log(WORLD__CLIENT, "New connection from %s:%d, processing connection", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
> Client* client = new Client(eqsi);
> // @merth: client->zoneattempt=0;
> client_list.Add(client);
> }
diff C:/1106/common/ruletypes.h C:/vztz/common/ruletypes.h
69a70
> RULE_BOOL ( World, UseBannedIPsTable, false ) //Lieka Edit: Check banned IP table before accepting connections to the world server. Default value: false (feature disabled)
diff C:/1106/common/database.h C:/vztz/common/database.h
139a140,141
> bool CheckBannedIPs(const char* loginIP); //Lieka Edit: Check incomming connection against banned IP table.
> bool AddBannedIP(char* bannedIP, const char* notes); //Lieka Edit: Add IP address to the Banned_IPs table.
diff C:/1106/common/database.cpp C:/vztz/common/database.cpp
207a208,257
> //Lieka: Get Banned IP Address List - Only return false if the incoming connection's IP address is not present in the banned_ips table.
> bool Database::CheckBannedIPs(const char* loginIP)
> {
> char errbuf[MYSQL_ERRMSG_SIZE];
> char *query = 0;
> MYSQL_RES *result;
> MYSQL_ROW row;
> //cout << "Checking against Banned IPs table."<< endl; //Lieka: Debugging
> if (RunQuery(query, MakeAnyLenString(&query, "SELECT ip_address FROM Banned_IPs WHERE ip_address='%s'", loginIP), errbuf, &result)) {
> safe_delete_array(query);
> if (mysql_num_rows(result) != 0)
> {
> //cout << loginIP << " was present in the banned IPs table" << endl; //Lieka: Debugging
> mysql_free_result(result);
> return true;
> }
> else
> {
> //cout << loginIP << " was not present in the banned IPs table." << endl; //Lieka: Debugging
> mysql_free_result(result);
> return false;
> }
> mysql_free_result(result);
> }
> else
> {
> cerr << "Error in CheckBannedIPs query '" << query << "' " << errbuf << endl;
> safe_delete_array(query);
> return true;
> }
>
> return true;
> }
>
> bool Database::AddBannedIP(char* bannedIP, const char* notes)
> {
> char errbuf[MYSQL_ERRMSG_SIZE];
> char *query = 0;
>
> if (!RunQuery(query, MakeAnyLenString(&query, "INSERT into Banned_IPs SET ip_address='%s', notes='%s'", bannedIP, notes), errbuf)) {
> cerr << "Error in ReserveName query '" << query << "' " << errbuf << endl;
> safe_delete_array(query);
> return false;
> }
> safe_delete_array(query);
> return true;
> }
>
> //End Lieka Edit
>
1458c1508
< return true;
---
> return true;
Dax
P.S. I would have just updated the thread in the submission forum, but it's locked.
