diff interpretiert code?



  • Hallo

    ich versuche von einer C++ Datei einen patch zu machen und benutze dabei den befehl "diff -u dateialt.cpp dateigepatcht". Aber diff wirft den code total durcheinander. Hier der betreffende code:

    static void send_chat(int cid, int team, const char *text)
    {
    	if(cid > -1 && cid < MAX_CLIENTS)
    	{
    		player *tmp = get_player(cid);
    		if(tmp->muted)
    		{
    			if(tmp->last_message_tick + 120*SERVER_TICK_SPEED > server_tick())
    			{
    				tmp->message_num++;
    				if(tmp->message_num > 3)
    				{
    					server_kick(cid,"You were kicked because of spamming.");
    				}
    				return;
    			}
    			else
    			{
    				tmp->muted = false;
    				tmp->message_num = 0;
    				tmp->last_message_tick = server_tick();
    			}
    		}
    		else
    		{
    			if(tmp->last_message_tick + 30*SERVER_TICK_SPEED > server_tick())
    			{
    				if(tmp->message_num > 8)
    				{
    					tmp->muted = true;
    					tmp->message_num = 0;
    					char *muting = (char *)malloc(sizeof(char) * 200);
    					sprintf(muting, "%s was muted for 2 minutes because of spamming.", server_clientname(cid));
    					NETMSG_SV_CHAT msg;
    					msg.team = 0;
    					msg.cid = -1;
    					msg.message = muting;
    					msg.pack(MSGFLAG_VITAL);
    					server_send_msg(-1);
    					free(muting);
    					return;
    				}
    				else
    					tmp->message_num++;
    			}
    			else
    			{
    				tmp->last_message_tick = server_tick();
    				tmp->message_num = 0;
    			}
    		}
    	}
    	if(cid >= 0 && cid < MAX_CLIENTS)                    //ab hier der alte code, davor hinzugefügter code
    		dbg_msg("chat", "%d:%d:%s: %s", cid, team, server_clientname(cid), text);
    	else
    		dbg_msg("chat", "*** %s", text);
    
    	if(team == CHAT_ALL)
    	{
    		NETMSG_SV_CHAT msg;
    		msg.team = 0;
    		msg.cid = cid;
    		msg.message = text;
    		msg.pack(MSGFLAG_VITAL);
    		server_send_msg(-1);
    	}
    	else
    	{
    		NETMSG_SV_CHAT msg;
    		msg.team = 1;
    		msg.cid = cid;
    		msg.message = text;
    		msg.pack(MSGFLAG_VITAL);
    
    		for(int i = 0; i < MAX_CLIENTS; i++)
    		{
    			if(players[i].client_id != -1 && players[i].team == team)
    				server_send_msg(i);
    		}
    	}
    }
    

    an dem kommentar(Z. 53) sieht man bis wo neuer code steht. hier nun die ausgabe von diff dazu:

    @@ -39,25 +39,53 @@
    
     static void send_chat(int cid, int team, const char *text)
     {
    +	if(cid > -1 && cid < MAX_CLIENTS)
     	if(cid >= 0 && cid < MAX_CLIENTS)
    +		player *tmp = get_player(cid);
    +		if(tmp->muted)
     		dbg_msg("chat", "%d:%d:%s: %s", cid, team, server_clientname(cid), text);
    +			if(tmp->last_message_tick + 120*SERVER_TICK_SPEED > server_tick())
     	else
    +				tmp->message_num++;
    +				if(tmp->message_num > 3)
     		dbg_msg("chat", "*** %s", text);
    +					server_kick(cid,"You were kicked because of spamming.");
    
    +				return;
     	if(team == CHAT_ALL)
     	{
     		NETMSG_SV_CHAT msg;
    +				tmp->muted = false;
    +				tmp->message_num = 0;
    +				tmp->last_message_tick = server_tick();
     		msg.team = 0;
     		msg.cid = cid;
     		msg.message = text;
     		msg.pack(MSGFLAG_VITAL);
    +			if(tmp->last_message_tick + 30*SERVER_TICK_SPEED > server_tick())
     		server_send_msg(-1);
    +				if(tmp->message_num > 8)
     	}
    +					tmp->muted = true;
    +					tmp->message_num = 0;
    +					char *muting = (char *)malloc(sizeof(char) * 200);
    +					sprintf(muting, "%s was muted for 2 minutes because of spamming.", server_clientname(cid));
    +					NETMSG_SV_CHAT msg;
    +					msg.team = 0;
    +					msg.cid = -1;
    +					msg.message = muting;
    +					msg.pack(MSGFLAG_VITAL);
    +					server_send_msg(-1);
    +					free(muting);
    +					return;
     	else
     	{
    +					tmp->message_num++;
     		NETMSG_SV_CHAT msg;
     		msg.team = 1;
     		msg.cid = cid;
    +				tmp->last_message_tick = server_tick();
    +				tmp->message_num = 0;
     		msg.message = text;
     		msg.pack(MSGFLAG_VITAL);
    

    btw: hoffentlich das richtige forum

    danke
    scosu


Log in to reply