Difference for server/c_party.c from version 1.12 to 1.13


version 1.12 version 1.13
Line 1
 
Line 1
 /*  /*
  * static char *rcsid_c_party_c =   * static char *rcsid_c_party_c =
  *   "$Id: c_party.c,v 1.12 2005/08/12 08:18:59 ryo_saeba Exp $";   *   "$Id: c_party.c,v 1.13 2005/09/24 09:28:05 ryo_saeba Exp $";
  */   */
   
 /*  /*
Line 38
 
Line 38
 partylist * form_party(object *op, const char *params, partylist * firstparty, partylist * lastparty) {  partylist * form_party(object *op, const char *params, partylist * firstparty, partylist * lastparty) {
   
     partylist * newparty;      partylist * newparty;
       int player_count;
     int nextpartyid;      int nextpartyid;
       player *pl;
   
     if(firstparty == NULL) {      if(firstparty == NULL) {
         nextpartyid = 1;          nextpartyid = 1;
Line 58
 
Line 60
     newparty->partyleader = strdup_local(op->name);      newparty->partyleader = strdup_local(op->name);
     if(firstparty != NULL)      if(firstparty != NULL)
         lastparty->next = newparty;          lastparty->next = newparty;
       /*
        * The player might already be a member of a party, if so, he will be leaving
        * it, so check if there are any other members and if not, delete the party
        */
       player_count=0;
       if (op->contr->party!=NULL) {
       for (pl=first_player;pl->next!=NULL;pl=pl->next) {
        if (pl->party==op->contr->party && op->contr!=pl)
        player_count++;
    }
    if (player_count == 0)
        remove_party(op->contr->party);
       }
     new_draw_info_format(NDI_UNIQUE, 0, op,      new_draw_info_format(NDI_UNIQUE, 0, op,
  "You have formed party: %s",newparty->partyname);   "You have formed party: %s",newparty->partyname);
       op->contr->party=newparty;
     return newparty;      return newparty;
 }  }
   
   int remove_party(partylist *target_party) {
       partylist *tmpparty;
       partylist *previousparty;
       partylist *nextparty;
       player *pl;
      
       if (firstparty==NULL) {
    LOG(llevDebug, "couldn't remove party %s from party list, no firstparty defined",
        target_party->partyname);
    return 1;
       }
       for (pl=first_player;pl!=NULL;pl=pl->next)
    if (pl->party==target_party) pl->party=NULL;
      
       /* special case-ism for parties at the beginning and end of the list */
       if (target_party==firstparty) {
    firstparty=firstparty->next;
    free(target_party->passwd);
    #ifdef PARTY_KILL_LOG
        free(target_party->party_kills);
    #endif
    free(target_party);
    for (tmpparty=firstparty->next;tmpparty->next!=NULL;tmpparty->next)
        tmpparty->partyid--;
    return 0;
       }
       else if (target_party == lastparty) {
    for (tmpparty=firstparty;tmpparty->next!=NULL;tmpparty->next) {
        if (tmpparty->next=target_party) {
    lastparty=tmpparty;
    free(target_party->passwd);
    #ifdef PARTY_KILL_LOG
        free(target_party->party_kills);
    #endif
    free(target_party);
    return 0;
        }
    }
       }
       for (tmpparty=firstparty;tmpparty->next!=NULL;tmpparty->next)
    if (tmpparty->next == target_party)
        previousparty=tmpparty;
        nextparty=tmpparty->next->next;
        /* this should be safe, because we already dealt with the lastparty case */
       
        previousparty->next=nextparty;
        for (tmpparty=nextparty->next;tmpparty->next!=NULL;tmpparty->next)
        tmpparty->partyid--;
        free(target_party->passwd);
    #ifdef PARTY_KILL_LOG
        free(target_party->party_kills);
    #endif
    free(target_party);
        return 0;
   }
   
   /* Remove unused parties, this could be made to scale a lot better. */
   void obsolete_parties() {
       int player_count;
       player *pl;
       partylist *party;
   
       for (party=firstparty; party->next==NULL; party=party->next) {
       player_count=0;
    for (pl=first_player;pl->next!=NULL;pl=pl->next)
        if (pl->party==party) player_count++;
    if (player_count == 0)
        remove_party(party);
       }
   }
   
 char * find_party(int partynumber, partylist * party) {  char * find_party(int partynumber, partylist * party) {
   
     while(party != NULL) {      while(party != NULL) {
Line 120
 
Line 207
   
   tmppartylist = firstparty;    tmppartylist = firstparty;
   while(tmppartylist != NULL) {    while(tmppartylist != NULL) {
     if(op->contr->party_number_to_join == tmppartylist->partyid) {       if(op->contr->party_to_join->partyid == tmppartylist->partyid) {
         if(strcmp(op->contr->write_buf+1,tmppartylist->passwd) == 0)          if(strcmp(op->contr->write_buf+1,tmppartylist->passwd) == 0)
           return 0;            return 0;
         else          else
Line 134
 
Line 221
 void receive_party_password(object *op, char k) {  void receive_party_password(object *op, char k) {
    
   if(confirm_party_password(op) == 0) {    if(confirm_party_password(op) == 0) {
     partylist* joined_party = find_party_struct( op->contr->party_number_to_join );      partylist* joined_party = op->contr->party_to_join;
     char buf[ MAX_BUF ];      char buf[ MAX_BUF ];
     op->contr->party_number = op->contr->party_number_to_join;      op->contr->party = op->contr->party_to_join;
     op->contr->party_number_to_join = (-1);      op->contr->party_to_join = NULL;
     new_draw_info_format(NDI_UNIQUE, 0,op,      new_draw_info_format(NDI_UNIQUE, 0,op,
  "You have joined party: %s\n",joined_party->partyname);   "You have joined party: %s\n",joined_party->partyname);
     snprintf( buf, MAX_BUF, "%s joins party %s", op->name, joined_party->partyname );      snprintf( buf, MAX_BUF, "%s joins party %s", op->name, joined_party->partyname );
Line 147
 
Line 234
   }    }
   else {    else {
     new_draw_info(NDI_UNIQUE, 0,op,"You entered the wrong password");      new_draw_info(NDI_UNIQUE, 0,op,"You entered the wrong password");
     op->contr->party_number_to_join = (-1);      op->contr->party_to_join = NULL;
     op->contr->state = ST_PLAYING;      op->contr->state = ST_PLAYING;
     return;      return;
   }    }
Line 156
 
Line 243
 void send_party_message(object *op,char *msg)  void send_party_message(object *op,char *msg)
 {  {
   player *pl;    player *pl;
   int no=op->contr->party_number;  
   for(pl=first_player;pl!=NULL;pl=pl->next)    for(pl=first_player;pl!=NULL;pl=pl->next)
     if(pl->ob->contr->party_number==no && pl->ob!=op)      if(pl->ob->contr->party==op->contr->party && pl->ob!=op)
  new_draw_info(NDI_WHITE, 0, pl->ob, msg);   new_draw_info(NDI_WHITE, 0, pl->ob, msg);
 }  }
   
Line 181
 
Line 267
   char * currentparty; /* For iterating over linked list */    char * currentparty; /* For iterating over linked list */
   
   if(params == NULL) {    if(params == NULL) {
         if(op->contr->party_number<=0) {          if(op->contr->party==NULL) {
           new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");            new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");
           new_draw_info(NDI_UNIQUE, 0,op,"For help try: party help");            new_draw_info(NDI_UNIQUE, 0,op,"For help try: party help");
         }          }
         else {          else {
           currentparty = find_party(op->contr->party_number,firstparty);            currentparty = op->contr->party->partyname;
    new_draw_info_format(NDI_UNIQUE, 0, op,     new_draw_info_format(NDI_UNIQUE, 0, op,
  "You are a member of party %s.", currentparty);   "You are a member of party %s.", currentparty);
         }          }
Line 215
 
Line 301
       char buffer[80];        char buffer[80];
       float exp;        float exp;
   
       if(op->contr->party_number<=0)        if(op->contr->party==NULL)
  {   {
    new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");     new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");
    return 1;     return 1;
  }   }
       tmpparty = find_party_struct(op->contr->party_number);        tmpparty = op->contr->party;
       if(!tmpparty->kills)        if(!tmpparty->kills)
  {   {
    new_draw_info(NDI_UNIQUE,0,op,"You haven't killed anything yet.");     new_draw_info(NDI_UNIQUE,0,op,"You haven't killed anything yet.");
Line 259
 
Line 345
 #endif /* PARTY_KILL_LOG */  #endif /* PARTY_KILL_LOG */
   if(strncmp(params, "say ", 4)==0)    if(strncmp(params, "say ", 4)==0)
     {      {
          if(op->contr->party_number<=0)           if(op->contr->party==NULL)
             {              {
               new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");                new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");
               return 1;                return 1;
             }              }
          params += 4;           params += 4;
          currentparty = find_party(op->contr->party_number,firstparty);           currentparty = op->contr->party->partyname;
          snprintf(buf,MAX_BUF-1, "[%s] %s says: %s", currentparty, op->name, params);           snprintf(buf,MAX_BUF-1, "[%s] %s says: %s", currentparty, op->name, params);
          send_party_message(op,buf);           send_party_message(op,buf);
          new_draw_info_format(NDI_WHITE, 0,op,"[%s] You say: %s", currentparty, params);           new_draw_info_format(NDI_WHITE, 0,op,"[%s] You say: %s", currentparty, params);
Line 310
 
Line 396
   } /* form */    } /* form */
   
   if(strcmp(params, "leave")==0) {    if(strcmp(params, "leave")==0) {
     if(op->contr->party_number<=0)      int player_count;
       player *pl;
       if(op->contr->party==NULL)
       {        {
         new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");          new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");
         return 1;          return 1;
       }        }
     currentparty = find_party(op->contr->party_number,firstparty);      currentparty = op->contr->party->partyname;
     new_draw_info_format(NDI_UNIQUE, 0, op,      new_draw_info_format(NDI_UNIQUE, 0, op,
  "You leave party %s.",currentparty);   "You leave party %s.",currentparty);
     sprintf(buf,"%s leaves party %s.",op->name,currentparty);      sprintf(buf,"%s leaves party %s.",op->name,currentparty);
     send_party_message(op,buf);      send_party_message(op,buf);
     op->contr->party_number=-1;      op->contr->party=NULL;
     return 1;      return 1;
   }    }
   if(strcmp(params, "who")==0) {    if(strcmp(params, "who")==0) {
     player *pl;      player *pl;
     int no=op->contr->party_number;      int no=op->contr->party->partyid;
     if(no<=0) {      if(op->contr->party==NULL) {
       new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");        new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of any party.");
       return 1;        return 1;
     }      }
     new_draw_info_format(NDI_UNIQUE, 0, op,      new_draw_info_format(NDI_UNIQUE, 0, op,
  "Members of party: %s.",find_party(no,firstparty));   "Members of party: %s.",find_party(no,firstparty));
     for(pl=first_player;pl!=NULL;pl=pl->next)      for(pl=first_player;pl!=NULL;pl=pl->next)
       if(pl->ob->contr->party_number==no) {        if(pl->ob->contr->party==op->contr->party) {
    if (settings.set_title == TRUE) {     if (settings.set_title == TRUE) {
        if(pl->ob->contr->own_title[0]!='\0')         if(pl->ob->contr->own_title[0]!='\0')
    sprintf(buf,"%3d %s the %s",     sprintf(buf,"%3d %s the %s",
Line 354
 
Line 442
   
     params += 7;      params += 7;
   
     if(op->contr->party_number <= 0) {      if(op->contr->party == NULL) {
       new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of a party");        new_draw_info(NDI_UNIQUE, 0,op,"You are not a member of a party");
       return 1;        return 1;
     }      }
Line 366
 
Line 454
   
     tmplist = firstparty;      tmplist = firstparty;
     while(tmplist != NULL) {      while(tmplist != NULL) {
       if(tmplist->partyid == op->contr->party_number) {        if(tmplist == op->contr->party) {
         strcpy(tmplist->passwd,params);          strcpy(tmplist->passwd,params);
      new_draw_info_format(NDI_UNIQUE, 0, op,       new_draw_info_format(NDI_UNIQUE, 0, op,
      "The password for party %s is %s", tmplist->partyname,tmplist->passwd);       "The password for party %s is %s", tmplist->partyname,tmplist->passwd);
Line 421
 
Line 509
         return 1;          return 1;
       }        }
       else {        else {
         if(op->contr->party_number == firstparty->partyid) {          if(op->contr->party == firstparty) {
    new_draw_info_format(NDI_UNIQUE, 0, op,     new_draw_info_format(NDI_UNIQUE, 0, op,
  "You are already in party: %s"   "You are already in party: %s"
                   ,firstparty->partyname);                    ,firstparty->partyname);
Line 429
 
Line 517
         }          }
         /* found party player wants to join */          /* found party player wants to join */
         if(firstparty->passwd[0] == '\0') {          if(firstparty->passwd[0] == '\0') {
           op->contr->party_number = firstparty->partyid;            op->contr->party = firstparty;
       new_draw_info_format(NDI_UNIQUE, 0, op,        new_draw_info_format(NDI_UNIQUE, 0, op,
      "You have joined party: %s",firstparty->partyname);       "You have joined party: %s",firstparty->partyname);
           snprintf( buf, MAX_BUF, "%s joins party %s", op->name, firstparty->partyname );            snprintf( buf, MAX_BUF, "%s joins party %s", op->name, firstparty->partyname );
Line 446
 
Line 534
     tmpparty = firstparty;      tmpparty = firstparty;
     while(tmpparty != NULL) {      while(tmpparty != NULL) {
       if(strcmp(tmpparty->partyname,params) == 0) {        if(strcmp(tmpparty->partyname,params) == 0) {
         if(op->contr->party_number == tmpparty->partyid) {          if(op->contr->party == tmpparty) {
    new_draw_info_format(NDI_UNIQUE, 0, op,     new_draw_info_format(NDI_UNIQUE, 0, op,
  "You are already a member of party: %s"   "You are already a member of party: %s"
                   ,tmpparty->partyname);                    ,tmpparty->partyname);
Line 456
 
Line 544
           if(tmpparty->passwd[0] == '\0') {            if(tmpparty->passwd[0] == '\0') {
             new_draw_info_format(NDI_UNIQUE, 0, op,              new_draw_info_format(NDI_UNIQUE, 0, op,
          "You have joined party: %s",tmpparty->partyname);           "You have joined party: %s",tmpparty->partyname);
             op->contr->party_number = tmpparty->partyid;              op->contr->party = tmpparty;
             snprintf( buf, MAX_BUF, "%s joins party %s", op->name, tmpparty->partyname );              snprintf( buf, MAX_BUF, "%s joins party %s", op->name, tmpparty->partyname );
             send_party_message( op, buf );              send_party_message( op, buf );
             return 0;              return 0;
Line 490
 
Line 578
 #endif  #endif
   return 1;    return 1;
 }  }
   
   


Legend:
line(s) removed in v.1.12 
line(s) changed
 line(s) added in v.1.13

File made using version 1.98 of cvs2html by leaf at 2011-07-21 17:29