viewing paste Unknown #1223 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
{
    int i;
    struct map_session_data *sd, *tsd;
    struct party_data *p = NULL;
    struct guild *g = NULL;
    struct battleground_data *bg = NULL;
    int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
    struct s_mapiterator* iter;
 
    if( type != ALL_CLIENT && type != BG_LISTEN )
        nullpo_ret(bl);
 
    sd = BL_CAST(BL_PC, bl);
 
    switch(type) {
 
    case ALL_CLIENT: //All player clients.
    case BG_LISTEN:
        iter = mapit_getallusers();
        while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
        {
            if( type == BG_LISTEN && !(tsd->state.bg_listen || tsd->qd) )
                continue;
 
            if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
            { // packet must exist for the client version
                WFIFOHEAD(tsd->fd, len);
                memcpy(WFIFOP(tsd->fd,0), buf, len);
                WFIFOSET(tsd->fd,len);
            }
        }
        mapit_free(iter);
        break;
 
    case ALL_SAMEMAP: //All players on the same map
        iter = mapit_getallusers();
        while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
        {
            if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
            { // packet must exist for the client version
                WFIFOHEAD(tsd->fd, len);
                memcpy(WFIFOP(tsd->fd,0), buf, len);
                WFIFOSET(tsd->fd,len);
            }
        }
        mapit_free(iter);
        break;
 
    case AREA:
    case AREA_WOSC:
        if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
            clif_send (buf, len, bl, SELF);
    case AREA_WOC:
    case AREA_WOS:
        map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
            BL_PC, buf, len, bl, type);
        break;
    case AREA_CHAT_WOC:
        map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
            bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
        break;
 
    case CHAT:
    case CHAT_WOS:
        {
            struct chat_data *cd;
            if (sd) {
                cd = (struct chat_data*)map_id2bl(sd->chatID);
            } else if (bl->type == BL_CHAT) {
                cd = (struct chat_data*)bl;
            } else break;
            if (cd == NULL)
                break;
            for(i = 0; i < cd->users; i++) {
                if (type == CHAT_WOS && cd->usersd[i] == sd)
                    continue;
                if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
                    if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
                    {
                        WFIFOHEAD(fd,len);
                        memcpy(WFIFOP(fd,0), buf, len);
                        WFIFOSET(fd,len);
                    }
                }
            }
        }
        break;
 
    case CHAT_MAINCHAT: //[LuzZza]
        iter = mapit_getallusers();
        while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
        {
            if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
            { // packet must exist for the client version
                WFIFOHEAD(tsd->fd, len);
                memcpy(WFIFOP(tsd->fd,0), buf, len);
                WFIFOSET(tsd->fd,len);
            }
        }
        mapit_free(iter);
        break;
 
    case PARTY_AREA:
    case PARTY_AREA_WOS:
        x0 = bl->x - AREA_SIZE;
        y0 = bl->y - AREA_SIZE;
        x1 = bl->x + AREA_SIZE;
        y1 = bl->y + AREA_SIZE;
    case PARTY:
    case PARTY_WOS:
    case PARTY_SAMEMAP:
    case PARTY_SAMEMAP_WOS:
        if (sd && sd->status.party_id)
            p = party_search(sd->status.party_id);
            
        if (p) {
            for(i=0;i<MAX_PARTY;i++){
                if( (sd = p->data[i].sd) == NULL )
                    continue;
 
                if( !(fd=sd->fd) )
                    continue;
 
                if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
                    continue;
                
                if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
                    continue;
                
                if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
                    continue;
                
                if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
                { // packet must exist for the client version
                    WFIFOHEAD(fd,len);
                    memcpy(WFIFOP(fd,0), buf, len);
                    WFIFOSET(fd,len);
                }
            }
            if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
                break;
 
            iter = mapit_getallusers();
            while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
            {
                if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
                { // packet must exist for the client version
                    WFIFOHEAD(tsd->fd, len);
                    memcpy(WFIFOP(tsd->fd,0), buf, len);
                    WFIFOSET(tsd->fd,len);
                }
            }
            mapit_free(iter);
        }
        break;
 
    case DUEL:
    case DUEL_WOS:
        if (!sd || !sd->duel_group) break; //Invalid usage.
 
        iter = mapit_getallusers();
        while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
        {
            if( type == DUEL_WOS && bl->id == tsd->bl.id )
                continue;
            if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
            { // packet must exist for the client version
                WFIFOHEAD(tsd->fd, len);
                memcpy(WFIFOP(tsd->fd,0), buf, len);
                WFIFOSET(tsd->fd,len);
            }
        }
        mapit_free(iter);
        break;
 
    case SELF:
        if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
            WFIFOHEAD(fd,len);
            memcpy(WFIFOP(fd,0), buf, len);
            WFIFOSET(fd,len);
        }
        break;
 
    // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
    case GUILD_AREA:
    case GUILD_AREA_WOS:
        x0 = bl->x - AREA_SIZE;
        y0 = bl->y - AREA_SIZE;
        x1 = bl->x + AREA_SIZE;
        y1 = bl->y + AREA_SIZE;
    case GUILD_SAMEMAP:
    case GUILD_SAMEMAP_WOS:
    case GUILD:
    case GUILD_WOS:
    case GUILD_NOBG:
        if (sd && sd->status.guild_id)
            g = guild_search(sd->status.guild_id);
 
        if (g) {
            for(i = 0; i < g->max_member; i++) {
                if( (sd = g->member[i].sd) != NULL )
                {
                    if( !(fd=sd->fd) )
                        continue;
                    
                    if( type == GUILD_NOBG && sd->bg_id )
                        continue;
 
                    if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
                        continue;
                    
                    if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
                        continue;
 
                    if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
                        continue;
 
                    if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
                    { // packet must exist for the client version
                        WFIFOHEAD(fd,len);
                        memcpy(WFIFOP(fd,0), buf, len);
                        WFIFOSET(fd,len);
                    }
                }
            }
            if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
                break;
 
            iter = mapit_getallusers();
            while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
            {
                if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
                { // packet must exist for the client version
                    WFIFOHEAD(tsd->fd, len);
                    memcpy(WFIFOP(tsd->fd,0), buf, len);
                    WFIFOSET(tsd->fd,len);
                }
            }
            mapit_free(iter);
        }
        break;
 
    case BG_AREA:
    case BG_AREA_WOS:
        x0 = bl->x - AREA_SIZE;
        y0 = bl->y - AREA_SIZE;
        x1 = bl->x + AREA_SIZE;
        y1 = bl->y + AREA_SIZE;
    case BG_SAMEMAP:
    case BG_SAMEMAP_WOS:
    case BG:
    case BG_WOS:
        if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
        {
            for( i = 0; i < MAX_BG_MEMBERS; i++ )
            {
                if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
                    continue;
                if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
                    continue;
                if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
                    continue;
                if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
                    continue;
                if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
                { // packet must exist for the client version
                    WFIFOHEAD(fd,len);
                    memcpy(WFIFOP(fd,0), buf, len);
                    WFIFOSET(fd,len);
                }
            }
        }
        break;
 
    default:
        ShowError("clif_send: Unrecognized type %d\n",type);
        return -1;
    }
 
    return 0;
}
Viewed 784 times, submitted by Guest.