⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trade.c

📁 石器时代2.0完整版源代码.已经加入新功能. 在REDHAT9下GCC3.4编译成功.
💻 C
📖 第 1 页 / 共 3 页
字号:
				snprintf(msg, sizeof(msg), "T|%d|%s|I|%d|%s", fd, mycharaname, showindex, buf1 );				lssproto_TD_send(tofd, -1, msg);			}		}		break;   	case 'g':		{			char buf1[2048];			if( TRADE_HandleGold( meindex, showindex, message, buf1) == FALSE ){				print(" TRADE_Close_Err4:%d,%d,%s,%s ", meindex, showindex, message, buf1);				TRADE_Close(fd, meindex, message);				return;			}else{// 将欲交易之金钱传给对方				snprintf(msg, sizeof(msg), "T|%d|%s|G|%d|%s", fd, mycharaname, showindex, buf1);				lssproto_TD_send( tofd, -1, msg);			}		}		break;		case 'p':		{			char buf1[2048];			if( TRADE_HandlePet( meindex, showindex, message, buf1) == FALSE ){				print(" TRADE_Close_Err5:%d,%d,%s,%s ", meindex, showindex, message, buf1);				TRADE_Close(fd, meindex, message);				return;			}else{				snprintf(msg, sizeof(msg), "T|%d|%s|P|%d|%s",					fd, mycharaname, showindex, buf1);				lssproto_TD_send(tofd, -1, msg);			}		}		break;   	case 'k':   	{	    if((CONNECT_get_confirm(fd)==TRUE) &&						(CONNECT_get_confirm(tofd)==TRUE) ){//当双方都按下 lock				if( CHAR_getWorkInt(meindex, CHAR_WORKTRADEMODE) == CHAR_TRADE_LOCK ){					//andy_log					print("ANDY err 防止第二次进入!!\n");					return;//防止第二次进入				}				CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_LOCK);				//检查对方是否按下 ok//				if( CHAR_getWorkInt( toindex, CHAR_WORKTRADEMODE) != CHAR_TRADE_LOCK )return;							snprintf(msg, sizeof(msg), "T|%d|%s|A", fd, mycharaname);				lssproto_TD_send( tofd, -1, msg);				TRADE_SwapItem(meindex, toindex, message, fd, mycharaname, tofd, tocharaname);			}else{				if( CONNECT_get_confirm( fd) == TRUE ) return;				CONNECT_set_confirm(fd, TRUE);				snprintf( msg, sizeof(msg), "T|%d|%s|C", fd, mycharaname);				lssproto_TD_send( tofd, -1, msg);			}		}   	break;		case 'c':		{	    if( CONNECT_get_confirm( fd) == TRUE ) return;			CONNECT_set_confirm(fd, TRUE);			snprintf( msg, sizeof(msg), "T|%d|%s|C", fd, mycharaname);			lssproto_TD_send( tofd, -1, msg);		}		break;  }	return;}void TRADE_SwapItem( int meindex, int toindex, char* message, int fd, char* mycharaname, int tofd, char* tocharaname){   int result;   char msg[128], tmpmsg[128];   CONNECT_setTradeTmp(fd, message);   result = TRADE_CheckItembuf(fd, meindex, toindex, tofd, mycharaname, tocharaname);   toindex = CONNECT_getCharaindex(tofd);   if (!CHAR_CHECKINDEX(toindex))       return;   if (result == -1)   	strcpy(msg, TRADE_FAILED);   else if (result == -2)   	sprintf(msg, TRADE_ITEMFULL, mycharaname);   else if (result == -3)   	sprintf(msg, TRADE_ITEMFULL, tocharaname);   else if (result == -4)   	sprintf(msg, TRADE_RICH, mycharaname);   else if (result == -5)   	sprintf(msg, TRADE_POOR, mycharaname);   else if (result == -6)   	sprintf(msg, TRADE_RICH, tocharaname);   else if (result == -7)   	sprintf(msg, TRADE_POOR, tocharaname);   else if (result == -8)   	sprintf(msg, TRADE_TOORICH, mycharaname);   else if (result == -9)   	sprintf(msg, TRADE_TOORICH, tocharaname);   else if (result == -10)   	sprintf(msg, TRADE_PETFULL, mycharaname);   else if (result == -11)   	sprintf(msg, TRADE_PETFULL, tocharaname);   else if (result == -12)   	strcpy(msg, TRADE_VANISHITEM);   else if (result == -13)   	sprintf(msg, TRADE_POORLV, mycharaname);   else if (result == -14)   	sprintf(msg, TRADE_POORLV, tocharaname);   else if (result == -15)   	strcpy(msg, TRADE_FMPET);   else if (result == 1)   	strcpy(msg, TRADE_SUCCESS);   else if (result == 2)   	strcpy(msg, TRADE_LOCK);   if (result != 2){   	snprintf(tmpmsg, sizeof(tmpmsg), "W|%d|%s", fd, mycharaname);   	lssproto_TD_send(tofd, -1, tmpmsg);   	snprintf(tmpmsg, sizeof(tmpmsg), "W|%d|%s", tofd, tocharaname);   	lssproto_TD_send(fd, -1, tmpmsg);   		CHAR_setWorkInt(meindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE);	CHAR_setWorkInt(toindex, CHAR_WORKTRADEMODE, CHAR_TRADE_FREE);	CONNECT_setTradeTmp(fd, "");	CONNECT_setTradeTmp(tofd, "");	CHAR_sendTradeEffect( meindex, 0);	CHAR_sendTradeEffect( toindex, 0);   	   }	CHAR_sendStatusString(meindex, "i");	CHAR_sendStatusString(toindex, "i");	CHAR_sendStatusString(meindex, "P");	CHAR_sendStatusString(toindex, "P");	{		int j, petindex;		char msgbuf[256];		for(j = 0; j < CHAR_MAXPETHAVE; j++){			petindex = CHAR_getCharPet( meindex, j);			if( !CHAR_CHECKINDEX( petindex) ) continue;			CHAR_complianceParameter( petindex );			snprintf( msgbuf, sizeof( msgbuf ), "K%d", j );			CHAR_sendStatusString( meindex, msgbuf );			snprintf( msgbuf, sizeof( msgbuf ), "W%d", j );			CHAR_sendStatusString( meindex, msgbuf );		}		for(j = 0; j < CHAR_MAXPETHAVE; j++){			petindex = CHAR_getCharPet( toindex, j);			if( !CHAR_CHECKINDEX( petindex) ) continue;			CHAR_complianceParameter( petindex );			snprintf( msgbuf, sizeof( msgbuf ), "K%d", j );			CHAR_sendStatusString( toindex, msgbuf );			snprintf( msgbuf, sizeof( msgbuf ), "W%d", j );			CHAR_sendStatusString( toindex, msgbuf );		}	}   CHAR_talkToCli(meindex, -1, msg, CHAR_COLORYELLOW);   CHAR_talkToCli(toindex, -1, msg, CHAR_COLORYELLOW);   }int TRADE_CheckItembuf(int fd, int meindex, int toindex, int tofd, char* mycharaname, char* tocharaname){   char a[16], b[16], c[16], d[16], e[16], f[16];   char g[16], h[16], i[16], j[16], k[16], l[16], token[16];   int itemindex1 = 0, itemindex2 = 0, itemindex3 = 0;   int itemindex4 = 0, itemindex5 = 0, itemindex6 = 0;   int toitemindex1 = 0, toitemindex2 = 0, toitemindex3 = 0;   int toitemindex4 = 0, toitemindex5 = 0, toitemindex6 = 0;   int item1 = 0, item2 = 0, item4 = 0, item5 = 0, pet3 = 0, pet6 = 0;   int pet1 = 0, pet2 = 0;   int swapitem1 = 0, swapitem2 = 0, gold1 = 0, gold2 = 0;   char itembuf[256], toitembuf[256], buf[4048];      CONNECT_getTradeTmp(fd, itembuf, sizeof(itembuf));   CONNECT_getTradeTmp(tofd, toitembuf, sizeof(toitembuf));   // 比对双方之最後交易协定   if (getStringFromIndexWithDelim(itembuf, "|", 5, token, sizeof(token)) == TRUE)	   	strcpy(a, token);   if (getStringFromIndexWithDelim(itembuf, "|", 6, token, sizeof(token)) == TRUE)		itemindex1 = atoi(token);   if (getStringFromIndexWithDelim(itembuf, "|", 7, token, sizeof(token)) == TRUE)	   	strcpy(b, token);   if (getStringFromIndexWithDelim(itembuf, "|", 8, token, sizeof(token)) == TRUE)		itemindex2 = atoi(token);   if (getStringFromIndexWithDelim(itembuf, "|", 9, token, sizeof(token)) == TRUE)	   	strcpy(c, token);   if (getStringFromIndexWithDelim(itembuf, "|", 10, token, sizeof(token)) == TRUE)		itemindex3 = atoi(token);   if (getStringFromIndexWithDelim(itembuf, "|", 11, token, sizeof(token)) == TRUE)	   	strcpy(d, token);   if (getStringFromIndexWithDelim(itembuf, "|", 12, token, sizeof(token)) == TRUE)		itemindex4 = atoi(token);   if (getStringFromIndexWithDelim(itembuf, "|", 13, token, sizeof(token)) == TRUE)	   	strcpy(e, token);   if (getStringFromIndexWithDelim(itembuf, "|", 14, token, sizeof(token)) == TRUE)		itemindex5 = atoi(token);   if (getStringFromIndexWithDelim(itembuf, "|", 15, token, sizeof(token)) == TRUE)		strcpy(f, token);   if (getStringFromIndexWithDelim(itembuf, "|", 16, token, sizeof(token)) == TRUE)		itemindex6 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 5, token, sizeof(token)) == TRUE)	   	strcpy(g, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 6, token, sizeof(token)) == TRUE)		toitemindex1 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 7, token, sizeof(token)) == TRUE)	   	strcpy(h, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 8, token, sizeof(token)) == TRUE)		toitemindex2 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 9, token, sizeof(token)) == TRUE)	   	strcpy(i, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 10, token, sizeof(token)) == TRUE)		toitemindex3 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 11, token, sizeof(token)) == TRUE)	   	strcpy(j, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 12, token, sizeof(token)) == TRUE)		toitemindex4 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 13, token, sizeof(token)) == TRUE)	   	strcpy(k, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 14, token, sizeof(token)) == TRUE)		toitemindex5 = atoi(token);   if (getStringFromIndexWithDelim(toitembuf, "|", 15, token, sizeof(token)) == TRUE)	   	strcpy(l, token);   if (getStringFromIndexWithDelim(toitembuf, "|", 16, token, sizeof(token)) == TRUE)		toitemindex6 = atoi(token);   // shan hjj add 洗道具   if (itemindex1==itemindex2){        if (itemindex1!=-1){            return -1;        }   }   if (itemindex4==itemindex5){        if (itemindex4!=-1){              return -1;        }   }   // End   if ((strcmp(a, j) == 0) && (strcmp(b, k) == 0) && (strcmp(c,l) == 0)   	&& (strcmp(d, g) == 0) && (strcmp(e, h) == 0) && (strcmp(f, i) == 0)   	&& (itemindex1 == toitemindex4) && (itemindex2 == toitemindex5)   	&& (itemindex3 == toitemindex6) && (itemindex4 == toitemindex1)   	&& (itemindex5 == toitemindex2) && (itemindex6 == toitemindex3))   {   	// 检验双方物品栏是否有空位	if ((strcmp(a, "I") == 0) && (itemindex1 != -1)){		swapitem1--;		swapitem2++;	}	if ((strcmp(b, "I") == 0) && (itemindex2 != -1)){		swapitem1--;		swapitem2++;	}	if ((strcmp(d, "I") == 0) && (itemindex4 != -1)){		swapitem1++;		swapitem2--;	}	if ((strcmp(e, "I") == 0) && (itemindex5 != -1)){		swapitem1++;		swapitem2--;	}	if (swapitem1 > CHAR_findTotalEmptyItem(meindex))		return	-2;	toindex = CONNECT_getCharaindex(tofd);	if (!CHAR_CHECKINDEX(toindex))       return -1;	if (swapitem2 > CHAR_findTotalEmptyItem(toindex))		return	-3;	// 检查双方金钱	if ((strcmp(a, "G") == 0) && (itemindex1 != -1))	gold1 += itemindex1;	if ((strcmp(b, "G") == 0) && (itemindex2 != -1))	gold1 += itemindex2;	if ((strcmp(d, "G") == 0) && (itemindex4 != -1))	gold2 += itemindex4;	if ((strcmp(e, "G") == 0) && (itemindex5 != -1))	gold2 += itemindex5;	if (gold1 > CHAR_getMaxHaveGold( meindex) )	return	-4;	if (gold1 > CHAR_getInt(meindex, CHAR_GOLD))	return	-5;	if (gold2 > CHAR_getMaxHaveGold( toindex))	return	-6;	if (gold2 > CHAR_getInt(toindex, CHAR_GOLD))	return	-7;	if ((gold2 + CHAR_getInt(meindex, CHAR_GOLD) - gold1) > CHAR_getMaxHaveGold( meindex) )	return	-8;	if ((gold1 + CHAR_getInt(toindex, CHAR_GOLD) - gold2) > CHAR_getMaxHaveGold( toindex))	return	-9;	// 检查双方宠物		if ((strcmp(c, "P") == 0) && (itemindex3 != -1))	{		pet1--;	pet2++;	}	if ((strcmp(f, "P") == 0) && (itemindex6 != -1))	{		pet1++;	pet2--;	}	if ((pet1 > 1) || (pet2 > 1))	return	-10;	if ((pet1 == 1) && (CHAR_getCharPetElement( meindex) == -1))	return -10;	if ((pet2 == 1) && (CHAR_getCharPetElement( toindex) == -1))	return -11;	if ((strcmp(a, "I") == 0) && (itemindex1 != -1))		item1 = CHAR_getItemIndex(meindex, itemindex1);	else	item1 = -1;	if ((strcmp(b, "I") == 0) && (itemindex2 != -1))		item2 = CHAR_getItemIndex(meindex, itemindex2);	else	item2 = -1;	if ((strcmp(d, "I") == 0) && (itemindex4 != -1))		item4 = CHAR_getItemIndex(toindex, itemindex4);	else	item4 = -1;	if ((strcmp(e, "I") == 0) && (itemindex5 != -1))		item5 = CHAR_getItemIndex(toindex, itemindex5);	else	item5 = -1;	if (itemindex3 != -1)	{		if( CHAR_getInt( meindex, CHAR_RIDEPET) == itemindex3 )			return -1;		pet3 = CHAR_getCharPet(meindex, itemindex3);	}	else 	pet3 = -1;	if (itemindex6 != -1)	{		if( CHAR_getInt( toindex, CHAR_RIDEPET) == itemindex6 )			return -1;		pet6 = CHAR_getCharPet(toindex, itemindex6);	}	else	pet6 = -1;	if ((ITEM_getInt(item1, ITEM_VANISHATDROP) == 1)||		(ITEM_getInt(item2, ITEM_VANISHATDROP) == 1)||		(ITEM_getInt(item4, ITEM_VANISHATDROP) == 1)||		(ITEM_getInt(item5, ITEM_VANISHATDROP) ==1))			return	-12;	if( CHAR_getWorkInt( meindex, CHAR_PickAllPet) != TRUE )	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -