Ver Fonte

added new anti-hacker system in trade.c

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@1204 54d463be-8e91-2dee-dedb-b68131a5f0ec
Lupus há 20 anos atrás
pai
commit
ead09c7c4c
7 ficheiros alterados com 188 adições e 106 exclusões
  1. 5 0
      Changelog-SVN.txt
  2. 15 10
      conf-tmpl/msg_athena.conf
  3. 2 1
      src/map/battle.h
  4. 9 9
      src/map/clif.c
  5. 3 1
      src/map/intif.c
  6. 1 1
      src/map/intif.h
  7. 153 84
      src/map/trade.c

+ 5 - 0
Changelog-SVN.txt

@@ -1,5 +1,10 @@
 Date	Added
 
+03/06
+	* Added new anti-hacker trade protection from Freya. [Lupus]
+	  It also auto-ban hackers and broadcasts messages to all GMs. Good work, Yor!
+	* Misc fixes. [Lupus]
+	  2Shino: BTW Some players can't re-connect to the server. Due to the updated session checks in chrif.c
 03/05
 	* Reversed drop_rate0item option, corrected MVP Drop rate (thanks to Freya) [Lupus]
 03/04

+ 15 - 10
conf-tmpl/msg_athena.conf

@@ -266,6 +266,18 @@
 502: The day has arrived!
 503: The night has fallen...
 
+//Supernovice's Guardian Angel
+//actually.. new client msgtxt file contains these 3 lines... [Lupus]
+//----------------------------
+504: Guardian Angel, can you hear my voice? ^^;
+505: My name is %s, and I'm a Super Novice~
+506: Please help me~ t.t
+
+//Guilds Default Ranks/Positions [Not implemented yet]
+507: GuildMaster
+508: Newbie
+509: Position %d
+
 //mail system
 //----------------------
 510: You have no messages.
@@ -286,13 +298,6 @@
 525: Mail has been sent.
 526: You have new mail.
 
-//Supernovice's Guardian Angel
-//----------------------------
-540: Guardian Angel, can you hear my voice? ^^;
-541: My name is %s, and I'm a Super Novice~
-542: Please help me~ t.t
-
-//Guilds Default Ranks/Positions
-543: GuildMaster
-544: Newbie
-545: Position %d
+538: Hack on trade: character '%s' (account: %d) try to trade more items that he has.
+539: This player has %d of a kind of item (id: %d), and try to trade %d of them.
+540: This player has been definitivly blocked.

+ 2 - 1
src/map/battle.h

@@ -285,10 +285,11 @@ extern struct Battle_Config {
 	int day_duration; // added by [Yor]
 	int night_duration; // added by [Yor]
 	int ban_spoof_namer; // added by [Yor]
+	int ban_hack_trade; // added by [Yor]
 	int hack_info_GM_level; // added by [Yor]
 	int any_warp_GM_min_level; // added by [Yor]
 	int packet_ver_flag; // added by [Yor]
-	int muting_players; // added by [Apple]
+	int muting_players; // added by [PoW]
 	
 	int min_hair_style; // added by [MouseJstr]
 	int max_hair_style; // added by [MouseJstr]

+ 9 - 9
src/map/clif.c

@@ -7947,18 +7947,18 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <
 
 		// information is sended to all online GM
 		sprintf(message, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
-		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message, strlen(message) + 1);
+		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
 		if (strlen((char*)RFIFOP(fd,4)) == 0)
 			strcpy(message, " This player sends a void name and a void message.");
 		else
 			sprintf(message, " This player sends (name:message): '%s'.", RFIFOP(fd,4));
-		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message, strlen(message) + 1);
+		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
 		// message about the ban
 		if (battle_config.ban_spoof_namer > 0)
 			sprintf(message, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
 		else
 			sprintf(message, " This player hasn't been banned (Ban option is disabled).");
-		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message, strlen(message) + 1);
+		intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
 
 		// if we ban people
 		if (battle_config.ban_spoof_namer > 0) {
@@ -7994,15 +7994,15 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <
 		int next = pc_nextbaseexp(sd)>0 ? pc_nextbaseexp(sd) : sd->status.base_exp;
 		if (next > 0 && (sd->status.base_exp*100/next)%10 == 0) {
 			estr_lower((char*)RFIFOP(fd,4));
-			if (sd->state.snovice_flag == 0 && strstr((char*)RFIFOP(fd,4), msg_txt(540)))
+			if (sd->state.snovice_flag == 0 && strstr((char*)RFIFOP(fd,4), msg_txt(504)))
 				sd->state.snovice_flag = 1;
 			else if (sd->state.snovice_flag == 1) {
-				sprintf(message, msg_txt(541), sd->status.name);
+				sprintf(message, msg_txt(505), sd->status.name);
 				estr_lower(message);
 				if (strstr((char*)RFIFOP(fd,4), message))
 					sd->state.snovice_flag = 2;
 			}
-			else if (sd->state.snovice_flag == 2 && strstr((char*)RFIFOP(fd,4), msg_txt(542)))
+			else if (sd->state.snovice_flag == 2 && strstr((char*)RFIFOP(fd,4), msg_txt(506)))
 				sd->state.snovice_flag = 3;
 			else if (sd->state.snovice_flag == 3) {
 				int i;
@@ -10193,7 +10193,7 @@ void clif_parse_PMIgnore(int fd, struct map_session_data *sd) {	// Rewritten by
 					clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
 					if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
 						sprintf(output, "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
-						intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output, strlen(output) + 1);
+						intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
 					}
 					return;
 				} else if (pos == -1 && sd->ignore[i].name[0] == '\0')
@@ -10206,7 +10206,7 @@ void clif_parse_PMIgnore(int fd, struct map_session_data *sd) {	// Rewritten by
 				WFIFOSET(fd, packet_len_table[0x0d1]);
 				if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
 					sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
-					intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output, strlen(output) + 1);
+					intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
 					// send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
 					clif_wis_message(fd, wisp_server_name, "Add me in your ignore list, doesn't block my wisps.", strlen("Add me in your ignore list, doesn't block my wisps.") + 1);
 				}
@@ -10216,7 +10216,7 @@ void clif_parse_PMIgnore(int fd, struct map_session_data *sd) {	// Rewritten by
 				clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
 				if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
 					sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
-					intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output, strlen(output) + 1);
+					intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
 				}
 			}
 		// allow action (we remove all same nicks if they exist)

+ 3 - 1
src/map/intif.c

@@ -172,9 +172,11 @@ int intif_wis_replay(int id, int flag) {
 }
 
 // The transmission of GM only Wisp/Page from server to inter-server
-int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes, int mes_len) {
+int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes) {
+	int mes_len;
 	if (CheckForCharServer())
 		return 0;
+	mes_len = strlen(mes) + 1; // + null
 	WFIFOW(inter_fd,0) = 0x3003;
 	WFIFOW(inter_fd,2) = mes_len + 30;
 	memcpy(WFIFOP(inter_fd,4), Wisp_name, 24);

+ 1 - 1
src/map/intif.h

@@ -7,7 +7,7 @@ int intif_parse(int fd);
 int intif_GMmessage(char* mes,int len,int flag);
 
 int intif_wis_message(struct map_session_data *sd,char *nick,char *mes,int mes_len);
-int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes, int mes_len);
+int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes);
 
 int intif_saveaccountreg(struct map_session_data *sd);
 int intif_request_accountreg(struct map_session_data *sd);

+ 153 - 84
src/map/trade.c

@@ -1,3 +1,6 @@
+// $Id: trade.c 375 2005-03-04 21:33:31Z Yor $
+//#include <config.h>
+
 #include <stdio.h>
 #include <string.h>
 
@@ -8,45 +11,43 @@
 #include "pc.h"
 #include "npc.h"
 #include "battle.h"
-#include "nullpo.h"
-#include "log.h"
 #include "chrif.h"
+#include "intif.h"
+#include "atcommand.h"
+
+#include "nullpo.h"
 
 /*==========================================
  * 取引要請を相手に送る
  *------------------------------------------
  */
-void trade_traderequest(struct map_session_data *sd,int target_id)
-{
+void trade_traderequest(struct map_session_data *sd, int target_id) {
 	struct map_session_data *target_sd;
 
 	nullpo_retv(sd);
 
-	if((target_sd = map_id2sd(target_id)) != NULL){
-		if(!battle_config.invite_request_check) {
-			if(target_sd->guild_invite>0 || target_sd->party_invite>0){
-				clif_tradestart(sd,2);	// 相手はPT要請中かGuild要請中
+	if ((target_sd = map_id2sd(target_id)) != NULL) {
+		if (!battle_config.invite_request_check) {
+			if (target_sd->guild_invite > 0 || target_sd->party_invite > 0) {
+				clif_tradestart(sd, 2); // 相手はPT要請中かGuild要請中
 				return;
 			}
 		}
-		if((target_sd->trade_partner !=0) || (sd->trade_partner !=0)) {
-			trade_tradecancel(sd); //person is in another trade
-		}
-		else{
-			if((pc_isGM(sd) < 60) && (sd->bl.m != target_sd->bl.m
-			 || (sd->bl.x - target_sd->bl.x <= -5 || sd->bl.x - target_sd->bl.x >= 5)
-			 || (sd->bl.y - target_sd->bl.y <= -5 || sd->bl.y - target_sd->bl.y >= 5))) {
-				clif_tradestart(sd,0); //too far
-			}
-			else if(sd!=target_sd) {
+		if ((target_sd->trade_partner != 0) || (sd->trade_partner != 0)) {
+			trade_tradecancel(sd); // person is in another trade
+		} else {
+			if (sd->bl.m != target_sd->bl.m ||
+			    (sd->bl.x - target_sd->bl.x <= -5 || sd->bl.x - target_sd->bl.x >= 5) ||
+			    (sd->bl.y - target_sd->bl.y <= -5 || sd->bl.y - target_sd->bl.y >= 5)) {
+				clif_tradestart(sd, 0); // too far
+			} else if (sd != target_sd) {
 				target_sd->trade_partner = sd->status.account_id;
 				sd->trade_partner = target_sd->status.account_id;
-				clif_traderequest(target_sd,sd->status.name);
+				clif_traderequest(target_sd, sd->status.name);
 			}
 		}
-	}
-	else{
-		clif_tradestart(sd,1); //character does not exist
+	} else {
+		clif_tradestart(sd, 1); // character does not exist
 	}
 }
 
@@ -54,34 +55,94 @@ void trade_traderequest(struct map_session_data *sd,int target_id)
  * 取引要請
  *------------------------------------------
  */
-void trade_tradeack(struct map_session_data *sd,int type)
-{
+void trade_tradeack(struct map_session_data *sd, int type) {
 	struct map_session_data *target_sd;
 
 	nullpo_retv(sd);
 
-	if((target_sd = map_id2sd(sd->trade_partner)) != NULL){
-		clif_tradestart(target_sd,type);
-		clif_tradestart(sd,type);
-		if(type == 4){ // Cancel
-			sd->deal_locked =0;
-			sd->trade_partner=0;
-			target_sd->deal_locked=0;
-			target_sd->trade_partner=0;
+	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
+		clif_tradestart(target_sd, type);
+		clif_tradestart(sd, type);
+		if (type == 4) { // Cancel
+			sd->deal_locked = 0;
+			sd->trade_partner = 0;
+			target_sd->deal_locked = 0;
+			target_sd->trade_partner = 0;
 		}
-		if(sd->npc_id != 0)
+		if (sd->npc_id != 0)
 			npc_event_dequeue(sd);
-		if(target_sd->npc_id != 0)
+		if (target_sd->npc_id != 0)
 			npc_event_dequeue(target_sd);
 	}
 }
 
+/*==========================================
+ * Check here hacker for duplicate item in trade
+ * normal client refuse to have 2 same types of item (except equipment) in same trade window
+ * normal client authorise only no equiped item and only from inventory
+ *------------------------------------------
+ */
+int impossible_trade_check(struct map_session_data *sd) {
+	struct item inventory[MAX_INVENTORY];
+	char message_to_gm[200];
+	int i, index;
+
+	nullpo_retr(0, sd);
+
+	// get inventory of player
+	memcpy(&inventory, &sd->status.inventory, sizeof(struct item) * MAX_INVENTORY);
+
+/* remove this part: arrows can be trade and equiped
+	// remove equiped items (they can not be trade)
+	for (i = 0; i < MAX_INVENTORY; i++)
+		if (inventory[i].nameid > 0 && inventory[i].equip)
+			memset(&inventory[i], 0, sizeof(struct item));
+*/
+
+	// check items in player inventory
+	for(i = 0; i < 10; i++)
+		if (sd->deal_item_amount[i] < 0) { // negativ? -> hack
+//			printf("Negativ amount in trade, by hack!\n"); // normal client send cancel when we type negativ amount
+			return -1;
+		} else if (sd->deal_item_amount[i] > 0) {
+			index = sd->deal_item_index[i] - 2;
+			inventory[index].amount -= sd->deal_item_amount[i]; // remove item from inventory
+//			printf("%d items left\n", inventory[index].amount);
+			if (inventory[index].amount < 0) { // if more than the player have -> hack
+//				printf("A player try to trade more items that he has: hack!\n");
+				sprintf(message_to_gm, msg_txt(538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has.
+				intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
+				sprintf(message_to_gm, msg_txt(539), sd->status.inventory[index].amount, sd->status.inventory[index].nameid, sd->status.inventory[index].amount - inventory[index].amount); // This player has %d of a kind of item (id: %d), and try to trade %d of them.
+				intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
+				// if we block people
+				if (battle_config.ban_hack_trade < 0) {
+					chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
+					clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
+					// message about the ban
+					sprintf(message_to_gm, msg_txt(540), battle_config.ban_spoof_namer); //  This player has been definitivly blocked.
+				// if we ban people
+				} else if (battle_config.ban_hack_trade > 0) {
+					chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_hack_trade, 0); // type: 2 - ban (year, month, day, hour, minute, second)
+					clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
+					// message about the ban
+					sprintf(message_to_gm, msg_txt(507), battle_config.ban_spoof_namer); //  This player has been banned for %d minute(s).
+				} else {
+					// message about the ban
+					sprintf(message_to_gm, msg_txt(508)); //  This player hasn't been banned (Ban option is disabled).
+				}
+				intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
+				return 1;
+			}
+		}
+
+	return 0;
+}
+
 /*==========================================
  * アイテム追加
  *------------------------------------------
  */
-void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
-{
+void trade_tradeadditem(struct map_session_data *sd, int index, int amount) {
 	struct map_session_data *target_sd;
 	int trade_i;
 	int trade_weight = 0;
@@ -90,7 +151,7 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
 	nullpo_retv(sd);
 
 	if (((target_sd = map_id2sd(sd->trade_partner)) != NULL) && (sd->deal_locked < 1)){
-		if (index < 2 || index >= MAX_INVENTORY + 2){
+		if (index < 2 || index >= MAX_INVENTORY + 2) {
 			if (index == 0) {
 				if (amount > 0 && amount <= MAX_ZENY && amount <= sd->status.zeny && // check amount
 				    (target_sd->status.zeny + amount) <= MAX_ZENY) { // fix positiv overflow
@@ -109,7 +170,7 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
 					trade_weight += sd->inventory_data[index-2]->weight * amount;
 					if (target_sd->weight + trade_weight > target_sd->max_weight){
 						clif_tradeitemok(sd, index, 1); // fail to add item -- the player was over weighted.
-						amount = 0; // [MouseJstr]
+						amount = 0;
 					} else {
 						for(c = 0; c == trade_i - 1; c++) { // re-deal exploit protection [Valaris]
 							if (sd->deal_item_index[c] == index) {
@@ -119,6 +180,10 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
 						}
 						sd->deal_item_index[trade_i] = index;
 						sd->deal_item_amount[trade_i] += amount;
+						if (impossible_trade_check(sd)) { // check exploit (trade more items that you have)
+							trade_tradecancel(sd);
+							return;
+						}
 						clif_tradeitemok(sd, index, 0); // success to add item
 						clif_tradeadditem(sd, target_sd, index, amount);
 					}
@@ -135,21 +200,25 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
  * アイテム追加完了(ok押し)
  *------------------------------------------
  */
-void trade_tradeok(struct map_session_data *sd)
-{
+void trade_tradeok(struct map_session_data *sd) {
 	struct map_session_data *target_sd;
 	int trade_i;
 
 	nullpo_retv(sd);
 
 	// check items
-	for(trade_i=0;trade_i<10;trade_i++) {
-		int idx = sd->deal_item_index[trade_i]-2;
-		if(((idx >= 0) && (sd->deal_item_amount[trade_i]>sd->status.inventory[idx].amount)) || sd->deal_item_amount[trade_i]<0) {
+	for(trade_i = 0; trade_i < 10; trade_i++) {
+		if (sd->deal_item_amount[trade_i] > sd->status.inventory[sd->deal_item_index[trade_i]-2].amount ||
+		    sd->deal_item_amount[trade_i] < 0) {
 			trade_tradecancel(sd);
 			return;
 		}
-	
+	}
+
+	// check exploit (trade more items that you have)
+	if (impossible_trade_check(sd)) {
+		trade_tradecancel(sd);
+		return;
 	}
 
 	// check zeny
@@ -157,12 +226,12 @@ void trade_tradeok(struct map_session_data *sd)
 		trade_tradecancel(sd);
 		return;
 	}
-	
-	if((target_sd = map_id2sd(sd->trade_partner)) != NULL){
-		sd->deal_locked=1;
-		clif_tradeitemok(sd,0,0);
-		clif_tradedeal_lock(sd,0);
-		clif_tradedeal_lock(target_sd,1);
+
+	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
+		sd->deal_locked = 1;
+		clif_tradeitemok(sd, 0, 0);
+		clif_tradedeal_lock(sd, 0);
+		clif_tradedeal_lock(target_sd, 1);
 	}
 }
 
@@ -170,38 +239,37 @@ void trade_tradeok(struct map_session_data *sd)
  * 取引キャンセル
  *------------------------------------------
  */
-void trade_tradecancel(struct map_session_data *sd)
-{
+void trade_tradecancel(struct map_session_data *sd) {
 	struct map_session_data *target_sd;
 	int trade_i;
 
 	nullpo_retv(sd);
 
-	if((target_sd = map_id2sd(sd->trade_partner)) != NULL){
-		for(trade_i=0; trade_i<10;trade_i++) { //give items back (only virtual)
-			if(sd->deal_item_amount[trade_i] != 0) {
-				clif_additem(sd,sd->deal_item_index[trade_i]-2,sd->deal_item_amount[trade_i],0);
-				sd->deal_item_index[trade_i] =0;
-				sd->deal_item_amount[trade_i]=0;
+	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
+		for(trade_i = 0; trade_i < 10; trade_i++) { // give items back (only virtual)
+			if (sd->deal_item_amount[trade_i] != 0) {
+				clif_additem(sd, sd->deal_item_index[trade_i] - 2, sd->deal_item_amount[trade_i], 0);
+				sd->deal_item_index[trade_i] = 0;
+				sd->deal_item_amount[trade_i] = 0;
 			}
-			if(target_sd->deal_item_amount[trade_i] != 0) {
-				clif_additem(target_sd,target_sd->deal_item_index[trade_i]-2,target_sd->deal_item_amount[trade_i],0);
-				target_sd->deal_item_index[trade_i] =0;
-				target_sd->deal_item_amount[trade_i]=0;
+			if (target_sd->deal_item_amount[trade_i] != 0) {
+				clif_additem(target_sd, target_sd->deal_item_index[trade_i] - 2, target_sd->deal_item_amount[trade_i], 0);
+				target_sd->deal_item_index[trade_i] = 0;
+				target_sd->deal_item_amount[trade_i] = 0;
 			}
 		}
-		if(sd->deal_zeny) {
-			clif_updatestatus(sd,SP_ZENY);
-			sd->deal_zeny=0;
+		if (sd->deal_zeny) {
+			clif_updatestatus(sd, SP_ZENY);
+			sd->deal_zeny = 0;
 		}
-		if(target_sd->deal_zeny) {
-			clif_updatestatus(target_sd,SP_ZENY);
-			target_sd->deal_zeny=0;
+		if (target_sd->deal_zeny) {
+			clif_updatestatus(target_sd, SP_ZENY);
+			target_sd->deal_zeny = 0;
 		}
-		sd->deal_locked =0;
-		sd->trade_partner=0;
-		target_sd->deal_locked=0;
-		target_sd->trade_partner=0;
+		sd->deal_locked = 0;
+		sd->trade_partner = 0;
+		target_sd->deal_locked = 0;
+		target_sd->trade_partner = 0;
 		clif_tradecancelled(sd);
 		clif_tradecancelled(target_sd);
 	}
@@ -220,8 +288,20 @@ void trade_tradecommit(struct map_session_data *sd) {
 
 	if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) {
 		if ((sd->deal_locked >= 1) && (target_sd->deal_locked >= 1)) { // both have pressed 'ok'
-			if (sd->deal_locked < 2) {sd->deal_locked = 2;} // set locked to 2
+			if (sd->deal_locked < 2) { // set locked to 2
+				sd->deal_locked = 2;
+			}
 			if (target_sd->deal_locked == 2) { // the other one pressed 'trade' too
+				// check exploit (trade more items that you have)
+				if (impossible_trade_check(sd)) {
+					trade_tradecancel(sd);
+					return;
+				}
+				// check exploit (trade more items that you have)
+				if (impossible_trade_check(target_sd)) {
+					trade_tradecancel(target_sd);
+					return;
+				}
 				// check zenys value against hackers
 				if (sd->deal_zeny >= 0 && sd->deal_zeny <= MAX_ZENY && sd->deal_zeny <= sd->status.zeny && // check amount
 				    (target_sd->status.zeny + sd->deal_zeny) <= MAX_ZENY && // fix positiv overflow
@@ -236,9 +316,6 @@ void trade_tradecommit(struct map_session_data *sd) {
 							if (sd->status.inventory[n].amount < sd->deal_item_amount[trade_i])
 								sd->deal_item_amount[trade_i] = sd->status.inventory[n].amount;
 
-							if(log_config.trade > 0)
-								log_trade(sd,target_sd,n,sd->deal_item_amount[trade_i]);
-
 							flag = pc_additem(target_sd, &sd->status.inventory[n], sd->deal_item_amount[trade_i]);
 							if (flag == 0)
 								pc_delitem(sd, n, sd->deal_item_amount[trade_i], 1);
@@ -253,9 +330,6 @@ void trade_tradecommit(struct map_session_data *sd) {
 							if (target_sd->status.inventory[n].amount < target_sd->deal_item_amount[trade_i])
 								target_sd->deal_item_amount[trade_i] = target_sd->status.inventory[n].amount;
 
-							if(log_config.trade > 0)
-								log_trade(target_sd,sd,n,target_sd->deal_item_amount[trade_i]);
-
 							flag = pc_additem(sd, &target_sd->status.inventory[n], target_sd->deal_item_amount[trade_i]);
 							if (flag == 0)
 								pc_delitem(target_sd, n, target_sd->deal_item_amount[trade_i], 1);
@@ -266,15 +340,10 @@ void trade_tradecommit(struct map_session_data *sd) {
 						}
 					}
 					if (sd->deal_zeny) {
-						if (log_config.trade > 0 && log_config.zeny > 0)
-							log_zeny(sd, target_sd, sd->deal_zeny);
 						sd->status.zeny -= sd->deal_zeny;
 						target_sd->status.zeny += sd->deal_zeny;
 					}
 					if (target_sd->deal_zeny) {
-						if (log_config.trade > 0 && log_config.zeny > 0)
-							log_zeny(target_sd, sd, sd->deal_zeny);
-
 						target_sd->status.zeny -= target_sd->deal_zeny;
 						sd->status.zeny += target_sd->deal_zeny;
 					}