00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "partytab.h"
00023
00024 #include "commandhandler.h"
00025
00026 #include "net/net.h"
00027 #include "net/partyhandler.h"
00028
00029 #include "resources/iteminfo.h"
00030 #include "resources/itemdb.h"
00031
00032 #include "utils/dtor.h"
00033 #include "utils/gettext.h"
00034 #include "utils/strprintf.h"
00035 #include "utils/stringutils.h"
00036
00037 PartyTab::PartyTab() :
00038 ChatTab(_("Party"))
00039 {
00040 }
00041
00042 PartyTab::~PartyTab()
00043 {
00044 }
00045
00046 void PartyTab::handleInput(const std::string &msg)
00047 {
00048 Net::getPartyHandler()->chat(msg);
00049 }
00050
00051 void PartyTab::showHelp()
00052 {
00053 chatLog(_("/help > Display this help."));
00054 chatLog(_("/create > Create a new party"));
00055 chatLog(_("/new > Alias of create"));
00056 chatLog(_("/invite > Invite a player to your party"));
00057 chatLog(_("/leave > Leave the party you are in"));
00058 chatLog(_("/kick > Kick some one from the party you are in"));
00059 chatLog(_("/item > Show/change party item sharing options"));
00060 chatLog(_("/exp > Show/change party experience sharing options"));
00061 }
00062
00063 bool PartyTab::handleCommand(const std::string &type, const std::string &args)
00064 {
00065 if (type == "help")
00066 {
00067 if (args == "create" || args == "new")
00068 {
00069 chatLog(_("Command: /new <party-name>"));
00070 chatLog(_("Command: /create <party-name>"));
00071 chatLog(_("These commands create a new party called <party-name>."));
00072 }
00073 else if (args == "invite")
00074 {
00075 chatLog(_("Command: /invite <nick>"));
00076 chatLog(_("This command invites <nick> to party with you."));
00077 chatLog(_("If the <nick> has spaces in it, enclose it in "
00078 "double quotes (\")."));
00079 }
00080 else if (args == "leave")
00081 {
00082 chatLog(_("Command: /leave"));
00083 chatLog(_("This command causes the player to leave the party."));
00084 }
00085 else if (args == "item")
00086 {
00087 chatLog(_("Command: /item <policy>"));
00088 chatLog(_("This command changes the party's item sharing policy."));
00089 chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
00090 "enable item sharing, or \"0\", \"no\", \"false\" to "
00091 "disable item sharing."));
00092 chatLog(_("Command: /item"));
00093 chatLog(_("This command displays the party's current item sharing policy."));
00094 }
00095 else if (args == "exp")
00096 {
00097 chatLog(_("Command: /exp <policy>"));
00098 chatLog(_("This command changes the party's experience sharing policy."));
00099 chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
00100 "enable experience sharing, or \"0\", \"no\", \"false\" to "
00101 "disable experience sharing."));
00102 chatLog(_("Command: /exp"));
00103 chatLog(_("This command displays the party's current experience sharing policy."));
00104 }
00105 else
00106 return false;
00107 }
00108 else if (type == "create" || type == "new")
00109 {
00110 if (args.empty())
00111 chatLog(_("Party name is missing."), BY_SERVER);
00112 else
00113 Net::getPartyHandler()->create(args);
00114 }
00115 else if (type == "invite")
00116 {
00117 Net::getPartyHandler()->invite(args);
00118 }
00119 else if (type == "leave")
00120 {
00121 Net::getPartyHandler()->leave();
00122 }
00123 else if (type == "kick")
00124 {
00125 Net::getPartyHandler()->kick(args);
00126 }
00127 else if (type == "item")
00128 {
00129 if (args.empty())
00130 {
00131 switch (Net::getPartyHandler()->getShareItems())
00132 {
00133 case PARTY_SHARE:
00134 chatLog(_("Item sharing enabled."), BY_SERVER);
00135 return true;
00136 case PARTY_SHARE_NO:
00137 chatLog(_("Item sharing disabled."), BY_SERVER);
00138 return true;
00139 case PARTY_SHARE_NOT_POSSIBLE:
00140 chatLog(_("Item sharing not possible."), BY_SERVER);
00141 return true;
00142 }
00143 }
00144
00145 char opt = CommandHandler::parseBoolean(args);
00146
00147 switch (opt)
00148 {
00149 case 1:
00150 Net::getPartyHandler()->setShareItems(PARTY_SHARE);
00151 break;
00152 case 0:
00153 Net::getPartyHandler()->setShareItems(PARTY_SHARE_NO);
00154 break;
00155 case -1:
00156 chatLog(strprintf(BOOLEAN_OPTIONS, "item"));
00157 }
00158 }
00159 else if (type == "exp")
00160 {
00161 if (args.empty())
00162 {
00163 switch (Net::getPartyHandler()->getShareExperience())
00164 {
00165 case PARTY_SHARE:
00166 chatLog(_("Experience sharing enabled."), BY_SERVER);
00167 return true;
00168 case PARTY_SHARE_NO:
00169 chatLog(_("Experience sharing disabled."), BY_SERVER);
00170 return true;
00171 case PARTY_SHARE_NOT_POSSIBLE:
00172 chatLog(_("Experience sharing not possible."), BY_SERVER);
00173 return true;
00174 }
00175 }
00176
00177 char opt = CommandHandler::parseBoolean(args);
00178
00179 switch (opt)
00180 {
00181 case 1:
00182 Net::getPartyHandler()->setShareExperience(PARTY_SHARE);
00183 break;
00184 case 0:
00185 Net::getPartyHandler()->setShareExperience(PARTY_SHARE_NO);
00186 break;
00187 case -1:
00188 chatLog(strprintf(BOOLEAN_OPTIONS, "exp"));
00189 }
00190 }
00191 else
00192 return false;
00193
00194 return true;
00195 }