1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/misc/command.h"
24 #include "nel/misc/file.h"
25 #include "nel/misc/i_xml.h"
26 #include "nel/misc/path.h"
27 #include "game_share/string_manager_sender.h"
28 #include "game_share/brick_families.h"
29 #include "game_share/ecosystem.h"
30 #include "game_share/people.h"
31 #include "game_share/roles.h"
32 //#include "game_share/jobs.h"
33 #include "game_share/skills.h"
34 #include "game_share/scores.h"
35 #include "game_share/characteristics.h"
36 #include "game_share/damage_types.h"
37 #include "game_share/power_types.h"
38 #include "input_output_service.h"
39 #include "string_manager.h"
41 using namespace NLMISC
;
42 using namespace NLNET
;
44 using namespace STRING_MANAGER
;
47 NLMISC_COMMAND(smReload
, "reload all translation files in string manager", "")
51 log
.displayNL("reload done.");
56 NLMISC_COMMAND(smReloadEventFactions
, "reload event factions", "[<filename>]")
62 SM
->reloadEventFactions(&log
, args
[0]);
64 SM
->reloadEventFactions(&log
);
66 log
.displayNL("reload done.");
71 NLMISC_COMMAND(smClearCache
, "clear the string cache in string manager", "")
77 NLMISC_COMMAND(smString
, "display a string from the string manager <string_id>", "")
85 NLMISC::fromString(args
[0], stringId
);
87 const ucstring
&str
= SM
->getString(stringId
);
89 log
.displayNL("String id %u = [%s]", stringId
, str
.toString().c_str());
94 // sm_test TEST_ITEM fyros_2h_axe_lvl_01_05.item
95 NLMISC_COMMAND(smTest
, "Send a test dyn string to a client (look at first phrase in phrase_en.txt)", "<client_name> <PHRASE NAME> [<param>]")
100 CCharacterInfos
*ci
= IOS
->getCharInfos(args
[0]);
103 // try to find a valid client
105 log
.displayNL("Unknown client '%s' !", args
[0].c_str());
110 TVectorParamCheck params
;
113 if (args
[1] == "TEST_SELF")
115 if (args
.size() != 2)
118 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_SELF", params
, &IosLocalSender
);
122 if (args
.size() != 3)
125 if (args
[1] == "TEST_ITEM")
127 // try to retreive the sheet id
128 NLMISC::CSheetId
sid(args
[2]);
129 if (sid
!= NLMISC::CSheetId::Unknown
)
131 p
.Type
= STRING_MANAGER::item
;
134 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_ITEM", params
, &IosLocalSender
);
138 log
.displayNL("Unknown item %s", args
[2].c_str());
142 else if (args
[1] == "TEST_PLAYER")
144 // try to retreive the player infos
145 CCharacterInfos
*other
= IOS
->getCharInfos(args
[2]);
148 p
.Type
= STRING_MANAGER::player
;
149 p
.setEId( other
->EntityId
);
151 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_PLAYER", params
, &IosLocalSender
);
155 log
.displayNL("Unknown player name '%s'", args
[2].c_str());
158 else if (args
[1] == "TEST_ENTITY")
160 // try to retreive the player infos
161 // CCharacterInfos *other = IOS->getCharInfos(args[2]);
162 CEntityId
eid(args
[2]);
163 if (eid
!= CEntityId::Unknown
)
165 p
.Type
= STRING_MANAGER::entity
;
168 // for some obscure reason, GCC 3.2.3 fail internaly to compile the push_back !
169 // so, I replaced the push_back with a resize + affectation.
172 // params.push_back(p);
174 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_ENTITY", params
, &IosLocalSender
);
178 log
.displayNL("Can't make entity ID from '%s'", args
[2].c_str());
181 else if (args
[1] == "TEST_SBRICK")
183 NLMISC::CSheetId
sid(args
[2]);
184 // BRICK_FAMILIES::TBrickFamily brick = BRICK_FAMILIES::toSBrickFamily(args[2]);
185 // if (brick != BRICK_FAMILIES::Unknown)
186 if (sid
!= CSheetId::Unknown
)
188 p
.Type
= STRING_MANAGER::sbrick
;
191 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_SBRICK", params
, &IosLocalSender
);
195 log
.displayNL("Unknown sbrick '%s'", args
[2].c_str());
199 else if (args
[1] == "TEST_ECO")
201 ECOSYSTEM::EECosystem eco
= ECOSYSTEM::stringToEcosystem(args
[2]);
202 if (eco
!= ECOSYSTEM::unknown
)
204 p
.Type
= STRING_MANAGER::ecosystem
;
207 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_ECO", params
, &IosLocalSender
);
211 log
.displayNL("Unknown ecosystem %s", args
[2].c_str());
215 else if (args
[1] == "TEST_CREATURE_MODEL")
217 std::string sheetName
= args
[2];
218 CSheetId
sid(sheetName
);
219 // EGSPD::CPeople::TPeople people = EGSPD::CPeople::fromString(args[1]);
220 if (sid
!= CSheetId::Unknown
)
222 p
.Type
= STRING_MANAGER::creature_model
;
225 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_CREATURE_MODEL", params
, &IosLocalSender
);
229 log
.displayNL("Unknown creature model '%s'", args
[2].c_str());
233 else if (args
[1] == "TEST_RACE")
235 //RACES::TRace race = RACES::toRaceId(args[1]);
236 EGSPD::CPeople::TPeople people
= EGSPD::CPeople::fromString(args
[2]);
237 if (people
!= EGSPD::CPeople::EndPeople
)
239 p
.Type
= STRING_MANAGER::race
;
242 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_RACE", params
, &IosLocalSender
);
246 log
.displayNL("Unknown race %s", args
[2].c_str());
250 /* else if (args[1] == "TEST_CAREER")
252 ROLES::ERole career = ROLES::toRoleId(args[2]);
253 if (career != ROLES::role_unknown)
255 p.Type = STRING_MANAGER::career;
258 dynId = sendStringToClient(ci->DataSetIndex, "TEST_CAREER", params, &IosLocalSender);
262 log.displayNL("Unknown career %s", args[2].c_str());
267 /* else if (args[1] == "TEST_JOB")
269 JOBS::TJob job = JOBS::toJob(args[2]);
270 if (job != JOBS::Unknown)
272 p.Type = STRING_MANAGER::job;
275 dynId = sendStringToClient(ci->DataSetIndex, "TEST_JOB", params, &IosLocalSender);
279 log.displayNL("Unknown job %s", args[2].c_str());
284 else if (args
[1] == "TEST_SKILL")
286 SKILLS::ESkills skill
= SKILLS::toSkill(args
[2]);
287 if (skill
!= SKILLS::unknown
)
289 p
.Type
= STRING_MANAGER::skill
;
292 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_SKILL", params
, &IosLocalSender
);
296 log
.displayNL("Unknown skill %s", args
[2].c_str());
300 else if (args
[1] == "TEST_BODYPART")
302 BODY::TBodyPart bodyPart
= BODY::toBodyPart(args
[2]);
303 if (bodyPart
!= BODY::UnknownBodyPart
)
305 p
.Type
= STRING_MANAGER::body_part
;
308 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_BODYPART", params
, &IosLocalSender
);
312 log
.displayNL("Unknown body part %s", args
[2].c_str());
316 else if (args
[1] == "TEST_SCORE")
318 SCORES::TScores score
= SCORES::toScore(args
[2]);
319 if (score
!= SCORES::unknown
)
321 p
.Type
= STRING_MANAGER::score
;
324 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_SCORE", params
, &IosLocalSender
);
328 log
.displayNL("Unknown score %s", args
[2].c_str());
332 else if (args
[1] == "TEST_CHARAC")
334 CHARACTERISTICS::TCharacteristics charac
= CHARACTERISTICS::toCharacteristic(args
[2]);
335 if (charac
!= CHARACTERISTICS::Unknown
)
337 p
.Type
= STRING_MANAGER::characteristic
;
340 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_CHARAC", params
, &IosLocalSender
);
344 log
.displayNL("Unknown characteristic %s", args
[2].c_str());
348 else if (args
[1] == "TEST_DAMAGE_TYPE")
350 DMGTYPE::EDamageType damageType
= DMGTYPE::stringToDamageType(args
[2]);
351 if (damageType
!= DMGTYPE::UNDEFINED
)
353 p
.Type
= STRING_MANAGER::damage_type
;
356 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_DAMAGE_TYPE", params
, &IosLocalSender
);
360 log
.displayNL("Unknown damage type %s", args
[2].c_str());
364 else if (args
[1] == "TEST_SPHRASE")
366 NLMISC::CSheetId
sid(args
[2]);
367 if (sid
!= NLMISC::CSheetId::Unknown
)
369 p
.Type
= STRING_MANAGER::sphrase
;
372 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_SPHRASE", params
, &IosLocalSender
);
376 log
.displayNL("Unknown sphrase Id %s", args
[2].c_str());
380 else if (args
[1] == "TEST_DYN_STRING")
383 NLMISC::fromString(args
[2], id
);
384 p
.Type
= STRING_MANAGER::dyn_string_id
;
387 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_DYN_STRING", params
, &IosLocalSender
);
389 else if (args
[1] == "TEST_STRING")
392 NLMISC::fromString(args
[2], id
);
393 p
.Type
= STRING_MANAGER::string_id
;
396 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_STRING", params
, &IosLocalSender
);
398 else if (args
[1] == "TEST_BOT_NAME")
402 log
.displayNL("Mission bot name as parameter !");
407 p
.Type
= STRING_MANAGER::bot_name
;
408 p
.Identifier
= args
[2];
410 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_BOT_NAME", params
, &IosLocalSender
);
413 else if (args
[1] == "TEST_POWER_TYPE")
415 POWERS::TPowerType powerType
= POWERS::toPowerType(args
[2]);
416 if (powerType
!= POWERS::UnknownType
)
418 p
.Type
= STRING_MANAGER::power_type
;
421 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_POWER_TYPE", params
, &IosLocalSender
);
425 log
.displayNL("Unknown power type %s", args
[2].c_str());
429 else if (args
[1] == "TEST_LITERAL")
431 ucstring str
= args
[2];
432 p
.Type
= STRING_MANAGER::literal
;
435 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_LITERAL", params
, &IosLocalSender
);
437 else if (args
[1] == "TEST_TITLE")
439 ucstring str
= args
[2];
440 p
.Type
= STRING_MANAGER::title
;
441 p
.Identifier
= str
.toString();
443 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_TITLE", params
, &IosLocalSender
);
445 else if (args
[1] == "TEST_EVENT_FACTION")
447 ucstring str
= args
[2];
448 p
.Type
= STRING_MANAGER::event_faction
;
449 p
.Identifier
= str
.toString();
451 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_EVENT_FACTION", params
, &IosLocalSender
);
453 else if (args
[1] == "TEST_CLASSIFICATION_TYPE")
455 EGSPD::CClassificationType::TClassificationType type
= EGSPD::CClassificationType::fromString(args
[2]);
456 if (type
!= EGSPD::CClassificationType::Unknown
)
458 p
.Type
= STRING_MANAGER::classification_type
;
461 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_CLASSIFICATION_TYPE", params
, &IosLocalSender
);
465 log
.displayNL("Unknown classification type %s", args
[2].c_str());
469 else if (args
[1] == "TEST_OUTPOST_WORD")
471 NLMISC::CSheetId
sid(args
[2]);
472 if (sid
!= CSheetId::Unknown
)
474 p
.Type
= STRING_MANAGER::outpost
;
477 dynId
= sendStringToClient(ci
->DataSetIndex
, "TEST_OUTPOST_WORD", params
, &IosLocalSender
);
481 log
.displayNL("Unknown sbrick '%s'", args
[2].c_str());
487 log
.displayNL("Unknow parameter %s", args
[2].c_str());
492 log
.displayNL("Dyn string send to client %s with ID = %u", args
[0].c_str(), dynId
);
498 NLMISC_COMMAND(sysCmd
, "Run preprogrammed system command(s)","commands are in the SystemCmd config variable")
500 CConfigFile::CVar
*sysCmds
= IService::getInstance()->ConfigFile
.getVarPtr("SystemCmd");
503 for (uint i
=0; i
<sysCmds
->size(); ++i
)
505 string cmd
= sysCmds
->asString(i
);
507 log
.displayNL("Invoking system command '%s'...", cmd
.c_str());
508 int ret
= system(cmd
.c_str());
509 log
.displayNL(" command returned %d", ret
);
514 log
.displayNL("Variable SystemCmd not found !");
521 //-----------------------------------------------
524 //-----------------------------------------------
525 NLMISC_COMMAND(mute
,"Mute or unmute a player. the player can be muted for a fixed period of time","<player>[<delay>]")
527 if( args
.size() == 0 )
532 if( args
.size() > 1 )
534 NLMISC::fromString(args
[1], delay
);
537 CCharacterInfos
* charInfos
= IOS
->getCharInfos( args
[0] );
538 if( charInfos
!= NULL
)
542 IOS
->getChatManager().getClient(charInfos
->DataSetIndex
).mute( delay
);
544 catch(const Exception
&e
)
546 nlwarning("<mite> %s",e
.what());
551 nlwarning("(mute) No infos about the character %s",args
[0].c_str());
560 //-----------------------------------------------
563 //-----------------------------------------------
564 NLMISC_COMMAND(remove
,"remove an entity from","<entity name>")
566 if( args
.size() < 1 )
571 CCharacterInfos
* charInfos
= IOS
->getCharInfos( args
[0] );
574 IOS
->removeEntity( charInfos
->DataSetIndex
);
578 nlwarning("<remove> Entity %s is not in the IOS",args
[0].c_str());
586 NLMISC_COMMAND(genImpulsion,"generate a fake impulsion, used to debug the CActionGeneric on the FS","<nb_uint8>")
588 if( args.size() != 1 )
594 CMessage msgout( "IMPULSION_ID" );
597 CBitMemStream stream;
600 NLMISC::fromString(args[0], count);
602 for (uint i = 0; i < count; i++)
605 //vector<uint8> &v = stream.bufferAsVector();
606 msgout.serialBufferWithSize ((uint8*)stream.buffer(), stream.length());
608 //const uint16 frontEndId = _Id.DynamicId;
609 sendMessageViaMirror ("FS", msgout);
616 NLMISC_COMMAND(display
,"display","")
622 NLMISC_COMMAND( displayChatClients
, "Display the list of clients", "" )
624 IOS
->getChatManager().displayChatClients(log
);
628 NLMISC_COMMAND( displayChatGroups
, "Display the list of chat groups, optionally, display universe chat group and/or player audience groups", "[universe] [player]" )
630 bool displayUniverse
= false;
631 bool playerAudience
= false;
632 vector
<string
> params
= args
;
633 while (!params
.empty())
635 if (params
[0] == "universe")
636 displayUniverse
= true;
637 else if (params
[0] == "player")
638 playerAudience
= true;
641 log
.displayNL("syntax error: invalid parameter '%s'", params
[0].c_str());
644 params
.erase(params
.begin());
647 IOS
->getChatManager().displayChatGroups(log
, displayUniverse
, playerAudience
);
651 NLMISC_COMMAND( displayChatAudience
, "Display the current chat dynamic audience for a player, optionally, force the update", "<playerId> [update]" )
657 CEntityId eid
= CEntityId(args
[0]);
659 if (args
.size() >= 2 && args
[1] == "update")
661 IOS
->getChatManager().displayChatAudience(log
, eid
, update
);
666 //-----------------------------------------------
669 //-----------------------------------------------
670 NLMISC_COMMAND(showChat
,"show or hide chat messages","")
672 ShowChat
= !ShowChat
;
679 NLMISC_COMMAND(chat
, "send message chat", "<char_name> <chat_group> <message> [<id>]")
684 CCharacterInfos
*ci
= IOS
->getCharInfos(args
[0]);
687 log
.displayNL("ERR: Unknown %s", args
[0].c_str());
691 TChanID chanId
= CEntityId::Unknown
;
692 TGroupId groupId
= CEntityId::Unknown
;
694 CChatGroup::TGroupType mode
;
695 if (args
[1].substr(0, 8) == "FACTION_" || args
[1].substr(0, 7) == "league_") // The current only translated dynamic chat
697 mode
= CChatGroup::dyn_chat
;
698 chanId
= IOS
->getChatManager().getChanId(args
[1]);
700 else if (args
[1].substr(0, 7) == "region:")
702 mode
= CChatGroup::region
;
703 groupId
.fromString(args
[1].substr(7).c_str());
705 else if (args
[1].substr(0, 6) == "guild:")
707 mode
= CChatGroup::guild
;
708 groupId
.fromString(args
[1].substr(6).c_str());
710 else if (args
[1].substr(0, 5) == "team:")
712 mode
= CChatGroup::team
;
713 groupId
.fromString(args
[1].substr(5).c_str());
717 mode
= CChatGroup::stringToGroupType(args
[1]);
720 string chat_group
= args
[1];
722 ucstr
.fromUtf8(args
[2]);
723 TDataSetRow rowId
= ci
->DataSetIndex
;
725 string rocketId
= "";
730 CChatGroup::TGroupType oldMode
= IOS
->getChatManager().getClient(rowId
).getChatMode();
731 TChanID oldChanId
= IOS
->getChatManager().getClient(rowId
).getDynChatChan();
732 TGroupId oldRegionId
=IOS
->getChatManager().getClient(rowId
).getRegionChatGroup();
735 IOS
->getChatManager().getClient(rowId
).setChatMode(mode
, chanId
);
737 if (mode
== CChatGroup::region
)
738 IOS
->getChatManager().getClient(rowId
).setRegionChatGroup(groupId
);
740 if (mode
== CChatGroup::guild
)
741 IOS
->getChatManager().getClient(rowId
).setGuildChatGroup(groupId
);
743 if (mode
== CChatGroup::team
)
744 IOS
->getChatManager().getClient(rowId
).setTeamChatGroup(groupId
);
747 IOS
->getChatManager().getClient(rowId
).updateAudience();
748 IOS
->getChatManager().chat(rowId
, ucstr
, rocketId
);
752 if (oldMode
== CChatGroup::dyn_chat
)
753 IOS
->getChatManager().getClient(rowId
).setChatMode(oldMode
, oldChanId
);
754 else if (oldMode
== CChatGroup::region
)
755 IOS
->getChatManager().getClient(rowId
).setRegionChatGroup(oldRegionId
);
757 IOS
->getChatManager().getClient(rowId
).setChatMode(oldMode
);
760 catch(const Exception
&e
)
762 nlwarning("<cbChatMessage> %s",e
.what());
768 NLMISC_COMMAND(farChat
, "send far message chat", "<char_name> <chat_id> <message> [<id>]")
775 string rocketId
= "";
777 string name
= args
[0];
778 ucstr
.fromUtf8(args
[2]);
782 IOS
->getChatManager().sendFarChat(name
, ucstr
, args
[1], rocketId
);
786 NLMISC_COMMAND(getRealName
, "getRealName", "<char_name>")
788 if (args
.size() != 1)
791 CCharacterInfos
*ci
= IOS
->getCharInfos(args
[0]);
794 log
.displayNL("ERR: Unknown %s", args
[0].c_str());
798 log
.displayNL("%s", ci
->ShortRealName
.c_str());