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 |
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; |
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 |
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 |
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: |
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 |
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: |
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; |
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)); |
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; |
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 |
} |
} |
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. |
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) |
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 ) { |
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; |
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; |
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 |
|
|
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); |
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 |