/[fgs]/fgs/src/roomproc.cc
ViewVC logotype

Diff of /fgs/src/roomproc.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by drysdam, Wed Sep 10 02:51:07 2003 UTC revision 1.10 by drysdam, Mon Sep 15 23:33:55 2003 UTC
# Line 44  enum GameType Line 44  enum GameType
44    
45  enum GovtType  enum GovtType
46  {  {
47    FASCISM,    FASCISM = 0,
48    ANARCHY,    ANARCHY = 1,
49    KILLARCHY    KILLARCHY = 2
50  };  };
51    
52  struct open_challenge  struct open_challenge
# Line 60  struct open_challenge Line 60  struct open_challenge
60    int mainTime;    int mainTime;
61    int extraTime;    int extraTime;
62    int movesTime;    int movesTime;
63      int wp;
64    int handi;    int handi;
65    float komi;    float komi;
66    int last_updated_by;    int last_updated_by;
# Line 76  struct open_game Line 77  struct open_game
77    int extraTime;    int extraTime;
78    int movesTime;    int movesTime;
79    std::string description;    std::string description;
80    std::pair<int, int> ratingRange;    std::pair<std::string, std::string> ratingRange;
81  };  };
82    
83  struct negotiated_game  struct negotiated_game
# Line 611  int com_roomlistbanned(int p, param_list Line 612  int com_roomlistbanned(int p, param_list
612    return COM_OK;    return COM_OK;
613  }  }
614    
615    //a banned user cannot visit the room.  Their membership
616    //status is not affected.
617  int com_roomban(int p, param_list param)  int com_roomban(int p, param_list param)
618  {  {
619    int r = param[0].val.integer;    int r = param[0].val.integer;
620    std::string login_to_ban = param[1].val.string;    std::string login_to_ban = param[1].val.string;
621    bool do_ban;    bool do_ban = false;
622    int uid;    int uid;
623    
624    // lookup room    // lookup room
# Line 632  int com_roomban(int p, param_list param) Line 635  int com_roomban(int p, param_list param)
635        break;        break;
636    
637      case KILLARCHY:      case KILLARCHY:
638        //no admins, everyone can ban        {
639        do_ban = true;        //no admins, everyone (WHO IS AN OCCUPANT) can ban
640          //(not member, because then they'd have to be registered)
641          //I guess this is an arbitrary decision
642          std::map<int, occupant>::iterator res = rm.occupants.find(p);
643          if(res != rm.occupants.end())
644            do_ban = true;
645          }
646          break;
647    
648      case ANARCHY:      case ANARCHY:
649        //no admins, nobody can ban        //no admins, nobody can ban
650      default:      default:
# Line 656  int com_roomunban(int p, param_list para Line 667  int com_roomunban(int p, param_list para
667  {  {
668    int r = param[0].val.integer;    int r = param[0].val.integer;
669    std::string login_to_unban = param[1].val.string;    std::string login_to_unban = param[1].val.string;
670    bool do_unban;    bool do_unban = false;
671    int uid;    int uid;
672    
673    // lookup room    // lookup room
# Line 673  int com_roomunban(int p, param_list para Line 684  int com_roomunban(int p, param_list para
684        break;        break;
685    
686      case KILLARCHY:      case KILLARCHY:
687        //no admins, everyone can ban        {
688        do_unban = true;        //no admins, everyone (WHO IS AN OCCUPANT) can ban
689          //(not member, because then they'd have to be registered)
690          //I guess this is an arbitrary decision
691          std::map<int, occupant>::iterator res = rm.occupants.find(p);
692          if(res != rm.occupants.end())
693            do_unban = true;
694          }
695          break;
696    
697      case ANARCHY:      case ANARCHY:
698        //no admins, nobody can ban        //no admins, nobody can ban
699      default:      default:
# Line 740  int com_roomlistgames(int p, param_list Line 759  int com_roomlistgames(int p, param_list
759  int com_roompostopengame(int p, param_list param)  int com_roompostopengame(int p, param_list param)
760  {  {
761    /*    /*
     TODO: do all this  
762      we're going to get this:      we're going to get this:
763      room gametype timetype (some number of time vars?) desc lowend highend      room gametype timetype (some number of time vars?) lowend highend desc
764      the player who sent the post is the inviter, duh      the player who sent the post is the inviter, duh
765    */    */
766    
767    int r = param[0].val.integer;    int r = param[0].val.integer;
768    GameType gtype = (GameType)0;    GameType gtype = (GameType)param[1].val.integer;
769    //  GameType gtype = (GameType)param[1].val.integer;    TimeType ttype = (TimeType)param[2].val.integer;
770    //  TimeType ttype = param[2].val.integer;    std::string lowrank = param[3].val.string;
771    std::string desc = param[1].val.string;    std::string highrank = param[4].val.string;
772    // std::string lowrank = param[4].val.string;    std::string desc = param[5].val.string;
   //  std::string highrank = param[5].val.string;  
773        
774    // lookup room    // lookup room
775    std::map<int, room>::iterator rmi = rarray.find(r);    std::map<int, room>::iterator rmi = rarray.find(r);
776    if(rmi == rarray.end()) return COM_NOSUCHROOM;    if(rmi == rarray.end()) return COM_NOSUCHROOM;
777    room& rm = rmi->second;    room& rm = rmi->second;
778    
779      // only non-silenced occupants can post games
780      std::map<int, occupant>::iterator res = rm.occupants.find(p);
781      if(res == rm.occupants.end()) return COM_NOTINROOM;
782      if(res->second.silenced) return COM_SILENCED;
783    
784    //TODO: Make sure nobody posts more than one open game    //TODO: Make sure nobody posts more than one open game
   //TODO: Make sure p is an occupant  
785    // find empty slot    // find empty slot
786    int i;    int i;  
787    for(i = 0; rm.open_games.find(i) != rm.open_games.end(); i++)    for(i = 0; rm.open_games.find(i) != rm.open_games.end(); i++)
788      ;      ;
789    std::stringstream ss;    std::stringstream ss;
# Line 772  int com_roompostopengame(int p, param_li Line 793  int com_roompostopengame(int p, param_li
793    
794    og.inviter = p;    og.inviter = p;
795    og.gameType = gtype;    og.gameType = gtype;
796      og.timeType = ttype;
797      og.ratingRange.first = lowrank;
798      og.ratingRange.second = highrank;
799    og.description = desc;    og.description = desc;
800    
801    rm.open_games.insert(std::pair<int, open_game>(i, og));    rm.open_games.insert(std::pair<int, open_game>(i, og));
# Line 790  int com_roomlistopengames(int p, param_l Line 814  int com_roomlistopengames(int p, param_l
814    if(rmi == rarray.end()) return COM_NOSUCHROOM;    if(rmi == rarray.end()) return COM_NOSUCHROOM;
815    room& rm = rmi->second;    room& rm = rmi->second;
816    
   //    TODO: do all this  
817    //reply with a list of open games    //reply with a list of open games
818    //game number, inviter, gametype, timetype, (time vars?), desc, lowend, highend    //game number, inviter gametype timetype (some number of time vars?) lowend highend desc
819    for(std::map<int, open_game>::iterator i = rm.open_games.begin();    for(std::map<int, open_game>::iterator i = rm.open_games.begin();
820        i != rm.open_games.end(); ++i) {        i != rm.open_games.end(); ++i) {
821      std::stringstream ss;      std::stringstream ss;
# Line 804  int com_roomlistopengames(int p, param_l Line 827  int com_roomlistopengames(int p, param_l
827      s += parray[i->second.inviter].login;      s += parray[i->second.inviter].login;
828      s += " ";      s += " ";
829      //gametype      //gametype
830      ss.str() = "";      ss.str("");
831      ss << i->second.gameType;      ss << i->second.gameType;
832      s += ss.str();      s += ss.str();
833      s += " ";      s += " ";
834        //timetype
835        ss.str("");
836        ss << i->second.timeType;
837        s += ss.str();
838        s += " ";
839        //lowend
840        s += i->second.ratingRange.first;
841        s += " ";
842        //highend
843        s += i->second.ratingRange.second;
844        s += " ";
845      //desc      //desc
846      s += i->second.description;      s += i->second.description;
847      s += "\n";      s += "\n";
848        s += "\n";
849            
850      ReplyOccupant(r, p, ROOM + ListOpenGames, s);      ReplyOccupant(r, p, ROOM + ListOpenGames, s);
851    }    }
# Line 820  int com_roomlistopengames(int p, param_l Line 855  int com_roomlistopengames(int p, param_l
855  int com_roommakegameoffer(int p, param_list param)  int com_roommakegameoffer(int p, param_list param)
856  {  {
857    /*    /*
     TODO: all the other params  
   
858      The info in an open_game struct is static and is just for      The info in an open_game struct is static and is just for
859      returning to the client what games are available.  The actual      returning to the client what games are available.  The actual
860      negotiation happens through the open_challenge struct.      negotiation happens through the open_challenge struct.
# Line 852  int com_roommakegameoffer(int p, param_l Line 885  int com_roommakegameoffer(int p, param_l
885    
886      we're going to get this:      we're going to get this:
887      room game_challenged gametype timetype (some number of time vars?)      room game_challenged gametype timetype (some number of time vars?)
888      handi komi existing_challenge_num (-1 if none)      wp handi komi existing_challenge_num (-1 if none)
889    
890        (if wp = 0, p is B, if 1, W)
891    
892    */    */
893    
894    int r = param[0].val.integer;    int r = param[0].val.integer;
895    int og = param[1].val.integer;    int og = param[1].val.integer;
896    GameType gtype = (GameType)param[2].val.integer;    GameType gtype = (GameType)param[2].val.integer;
897    int ocnum = param[3].val.integer;    TimeType ttype = (TimeType)param[3].val.integer;
898      bool wp = (param[4].val.integer == 1);
899      int handi = param[5].val.integer;
900      float komi = param[6].val.f;
901      int ocnum = param[7].val.integer;
902    
903    //TODO: If the challenger isn't between the ranks (and btw,    //TODO: If the challenger isn't between the ranks (and btw,
904    //we need a way for the inviter to exclude - and ? people)    //we need a way for the inviter to exclude - and ? people)
# Line 870  int com_roommakegameoffer(int p, param_l Line 909  int com_roommakegameoffer(int p, param_l
909    if(rmi == rarray.end()) return COM_NOSUCHROOM;    if(rmi == rarray.end()) return COM_NOSUCHROOM;
910    room& rm = rmi->second;    room& rm = rmi->second;
911    
912      // lookup open_game
913      std::map<int, open_game>::iterator ogi = rm.open_games.find(og);
914      if(ogi == rm.open_games.end()) return COM_NOSUCHOPENGAME;
915      open_game& ogm = ogi->second;
916    
917    //lookup challenge or create new if necessary    //lookup challenge or create new if necessary
918    int i;    int i;
919    if( ocnum < 0 ) {    if( ocnum < 0 ) {
# Line 882  int com_roommakegameoffer(int p, param_l Line 926  int com_roommakegameoffer(int p, param_l
926      std::map<int, open_challenge>::iterator oci = rm.open_challenges.find(ocnum);      std::map<int, open_challenge>::iterator oci = rm.open_challenges.find(ocnum);
927      if(oci == rm.open_challenges.end()) return COM_NOSUCHCHALLENGE;      if(oci == rm.open_challenges.end()) return COM_NOSUCHCHALLENGE;
928      i = oci->first;      i = oci->first;
   }  
929    
930    // lookup open_game      //don't allow hijacking of game challenges
931    std::map<int, open_game>::iterator ogi = rm.open_games.find(og);      if((p != ogm.inviter) && (p != rm.open_challenges[i].challenger))
932    if(ogi == rm.open_games.end()) return COM_NOSUCHOPENGAME;        return COM_NOSUCHCHALLENGE;
933    open_game& ogm = ogi->second;    }
934        
   //TODO: Make sure exist challenges don't get hijacked by  
   //      other players  
935    int p1;    int p1;
936    if(p != ogm.inviter) {    if(p != ogm.inviter) {
937      rm.open_challenges[i].challenger = p;      rm.open_challenges[i].challenger = p;
# Line 899  int com_roommakegameoffer(int p, param_l Line 940  int com_roommakegameoffer(int p, param_l
940      p1 = rm.open_challenges[i].challenger;      p1 = rm.open_challenges[i].challenger;
941    
942    rm.open_challenges[i].game_challenged = ogi->first;    rm.open_challenges[i].game_challenged = ogi->first;
943      rm.open_challenges[i].gameType = gtype;
944      rm.open_challenges[i].timeType = ttype;
945      if(wp)
946        rm.open_challenges[i].wp = p;
947      else
948        rm.open_challenges[i].wp = p1;
949      rm.open_challenges[i].handi = handi;
950      rm.open_challenges[i].komi = komi;
951    rm.open_challenges[i].last_updated_by = p;    rm.open_challenges[i].last_updated_by = p;
952    
953    std::stringstream ss;    std::stringstream ss;
# Line 906  int com_roommakegameoffer(int p, param_l Line 955  int com_roommakegameoffer(int p, param_l
955    ss << ogi->first;    ss << ogi->first;
956    s = ss.str();    s = ss.str();
957    s += " ";    s += " ";
958    ss.str() = " ";    ss.str("");
959    ss << i;    ss << i;
960    s += ss.str();    s += ss.str();
961    
# Line 984  int com_roomacceptgame(int p, param_list Line 1033  int com_roomacceptgame(int p, param_list
1033       in the "last updated by" field of the challenge.       in the "last updated by" field of the challenge.
1034    
1035       Format matches com_makegameoffer() and content must match the       Format matches com_makegameoffer() and content must match the
1036       given challenge num exactly.       given challenge num exactly, but with wp reversed
1037    */    */
1038    
1039    int r = param[0].val.integer;    int r = param[0].val.integer;
1040    int og = param[1].val.integer;    int og = param[1].val.integer;
1041    GameType gtype = (GameType)param[2].val.integer;    GameType gtype = (GameType)param[2].val.integer;
1042    int ocnum = param[3].val.integer;    TimeType ttype = (TimeType)param[3].val.integer;
1043      bool wp = (param[4].val.integer == 1);
1044      int handi = param[5].val.integer;
1045      float komi = param[6].val.f;
1046      int ocnum = param[7].val.integer;
1047    
1048    // lookup room    // lookup room
1049    std::map<int, room>::iterator rmi = rarray.find(r);    std::map<int, room>::iterator rmi = rarray.find(r);
# Line 1021  int com_roomacceptgame(int p, param_list Line 1074  int com_roomacceptgame(int p, param_list
1074    // error code?    // error code?
1075    if(gtype != oc.gameType)    if(gtype != oc.gameType)
1076      return COM_OK;      return COM_OK;
1077      if(ttype != oc.timeType)
1078        return COM_OK;
1079      //If the accepting player says he's W but the other
1080      //player didn't say that, or vice versa, it's no good
1081      if((wp && p != oc.wp) || (!wp && p == oc.wp))
1082        return COM_OK;
1083      if(handi != oc.handi)
1084        return COM_OK;
1085      if(komi != oc.komi)
1086        return COM_OK;
1087    
   //set white and black (TODO: "correctly")  
1088    int challenger = oc.challenger;    int challenger = oc.challenger;
1089    int wp = p;    int bp = (wp == p?p1:p);
   int bp = p1;  
1090    
1091    // lookup open_game    // lookup open_game
1092    //delete open_game (do before deleting challenges, just in case    //delete open_game (do before deleting challenges, just in case

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26