Add infos into target window
[ryzomcore.git] / ryzom / server / src / input_output_service / commands.cpp
blob02821eeb0071f0e36d98216b913e5fb3fb826e05
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
21 #include "stdpch.h"
22 // Nel Misc
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;
43 using namespace std;
44 using namespace STRING_MANAGER;
47 NLMISC_COMMAND(smReload, "reload all translation files in string manager", "")
49 SM->reload(&log);
51 log.displayNL("reload done.");
53 return true;
56 NLMISC_COMMAND(smReloadEventFactions, "reload event factions", "[<filename>]")
58 if (args.size() > 1)
59 return false;
61 if (args.size() == 1)
62 SM->reloadEventFactions(&log, args[0]);
63 else
64 SM->reloadEventFactions(&log);
66 log.displayNL("reload done.");
68 return true;
71 NLMISC_COMMAND(smClearCache, "clear the string cache in string manager", "")
73 SM->clearCache(&log);
74 return true;
77 NLMISC_COMMAND(smString, "display a string from the string manager <string_id>", "")
79 if (args.size() != 1)
81 return false;
84 uint32 stringId;
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());
91 return true;
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>]")
97 if (args.size() < 2)
98 return false;
100 CCharacterInfos *ci = IOS->getCharInfos(args[0]);
101 if (ci == NULL)
103 // try to find a valid client
105 log.displayNL("Unknown client '%s' !", args[0].c_str());
106 return false;
109 uint dynId;
110 TVectorParamCheck params;
111 TParam p;
113 if (args[1] == "TEST_SELF")
115 if (args.size() != 2)
116 return false;
118 dynId = sendStringToClient(ci->DataSetIndex, "TEST_SELF", params, &IosLocalSender);
120 else
122 if (args.size() != 3)
123 return false;
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;
132 p.SheetId = sid;
133 params.push_back(p);
134 dynId = sendStringToClient(ci->DataSetIndex, "TEST_ITEM", params, &IosLocalSender);
136 else
138 log.displayNL("Unknown item %s", args[2].c_str());
139 return true;
142 else if (args[1] == "TEST_PLAYER")
144 // try to retreive the player infos
145 CCharacterInfos *other = IOS->getCharInfos(args[2]);
146 if (other)
148 p.Type = STRING_MANAGER::player;
149 p.setEId( other->EntityId );
150 params.push_back(p);
151 dynId = sendStringToClient(ci->DataSetIndex, "TEST_PLAYER", params, &IosLocalSender);
153 else
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;
166 p.setEId( eid );
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.
170 params.resize(1);
171 params[0] = p;
172 // params.push_back(p);
174 dynId = sendStringToClient(ci->DataSetIndex, "TEST_ENTITY", params, &IosLocalSender);
176 else
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;
189 p.SheetId = sid;
190 params.push_back(p);
191 dynId = sendStringToClient(ci->DataSetIndex, "TEST_SBRICK", params, &IosLocalSender);
193 else
195 log.displayNL("Unknown sbrick '%s'", args[2].c_str());
196 return true;
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;
205 p.Enum = eco;
206 params.push_back(p);
207 dynId = sendStringToClient(ci->DataSetIndex, "TEST_ECO", params, &IosLocalSender);
209 else
211 log.displayNL("Unknown ecosystem %s", args[2].c_str());
212 return true;
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;
223 p.SheetId = sid;
224 params.push_back(p);
225 dynId = sendStringToClient(ci->DataSetIndex, "TEST_CREATURE_MODEL", params, &IosLocalSender);
227 else
229 log.displayNL("Unknown creature model '%s'", args[2].c_str());
230 return true;
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;
240 p.Enum = people;
241 params.push_back(p);
242 dynId = sendStringToClient(ci->DataSetIndex, "TEST_RACE", params, &IosLocalSender);
244 else
246 log.displayNL("Unknown race %s", args[2].c_str());
247 return true;
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;
256 p.Enum = career;
257 params.push_back(p);
258 dynId = sendStringToClient(ci->DataSetIndex, "TEST_CAREER", params, &IosLocalSender);
260 else
262 log.displayNL("Unknown career %s", args[2].c_str());
263 return true;
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;
273 p.Enum = job;
274 params.push_back(p);
275 dynId = sendStringToClient(ci->DataSetIndex, "TEST_JOB", params, &IosLocalSender);
277 else
279 log.displayNL("Unknown job %s", args[2].c_str());
280 return true;
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;
290 p.Enum = skill;
291 params.push_back(p);
292 dynId = sendStringToClient(ci->DataSetIndex, "TEST_SKILL", params, &IosLocalSender);
294 else
296 log.displayNL("Unknown skill %s", args[2].c_str());
297 return true;
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;
306 p.Enum = bodyPart;
307 params.push_back(p);
308 dynId = sendStringToClient(ci->DataSetIndex, "TEST_BODYPART", params, &IosLocalSender);
310 else
312 log.displayNL("Unknown body part %s", args[2].c_str());
313 return true;
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;
322 p.Enum = score;
323 params.push_back(p);
324 dynId = sendStringToClient(ci->DataSetIndex, "TEST_SCORE", params, &IosLocalSender);
326 else
328 log.displayNL("Unknown score %s", args[2].c_str());
329 return true;
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;
338 p.Enum = charac;
339 params.push_back(p);
340 dynId = sendStringToClient(ci->DataSetIndex, "TEST_CHARAC", params, &IosLocalSender);
342 else
344 log.displayNL("Unknown characteristic %s", args[2].c_str());
345 return true;
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;
354 p.Enum = damageType;
355 params.push_back(p);
356 dynId = sendStringToClient(ci->DataSetIndex, "TEST_DAMAGE_TYPE", params, &IosLocalSender);
358 else
360 log.displayNL("Unknown damage type %s", args[2].c_str());
361 return true;
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;
370 p.SheetId = sid;
371 params.push_back(p);
372 dynId = sendStringToClient(ci->DataSetIndex, "TEST_SPHRASE", params, &IosLocalSender);
374 else
376 log.displayNL("Unknown sphrase Id %s", args[2].c_str());
377 return true;
380 else if (args[1] == "TEST_DYN_STRING")
382 uint32 id;
383 NLMISC::fromString(args[2], id);
384 p.Type = STRING_MANAGER::dyn_string_id;
385 p.StringId = id;
386 params.push_back(p);
387 dynId = sendStringToClient(ci->DataSetIndex, "TEST_DYN_STRING", params, &IosLocalSender);
389 else if (args[1] == "TEST_STRING")
391 uint32 id;
392 NLMISC::fromString(args[2], id);
393 p.Type = STRING_MANAGER::string_id;
394 p.StringId = id;
395 params.push_back(p);
396 dynId = sendStringToClient(ci->DataSetIndex, "TEST_STRING", params, &IosLocalSender);
398 else if (args[1] == "TEST_BOT_NAME")
400 if (args.size() < 3)
402 log.displayNL("Mission bot name as parameter !");
403 return true;
405 else
407 p.Type = STRING_MANAGER::bot_name;
408 p.Identifier = args[2];
409 params.push_back(p);
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;
419 p.Enum = powerType;
420 params.push_back(p);
421 dynId = sendStringToClient(ci->DataSetIndex, "TEST_POWER_TYPE", params, &IosLocalSender);
423 else
425 log.displayNL("Unknown power type %s", args[2].c_str());
426 return true;
429 else if (args[1] == "TEST_LITERAL")
431 ucstring str = args[2];
432 p.Type = STRING_MANAGER::literal;
433 p.Literal = str;
434 params.push_back(p);
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();
442 params.push_back(p);
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();
450 params.push_back(p);
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;
459 p.Enum = type;
460 params.push_back(p);
461 dynId = sendStringToClient(ci->DataSetIndex, "TEST_CLASSIFICATION_TYPE", params, &IosLocalSender);
463 else
465 log.displayNL("Unknown classification type %s", args[2].c_str());
466 return true;
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;
475 p.SheetId = sid;
476 params.push_back(p);
477 dynId = sendStringToClient(ci->DataSetIndex, "TEST_OUTPOST_WORD", params, &IosLocalSender);
479 else
481 log.displayNL("Unknown sbrick '%s'", args[2].c_str());
482 return true;
485 else
487 log.displayNL("Unknow parameter %s", args[2].c_str());
488 return false;
492 log.displayNL("Dyn string send to client %s with ID = %u", args[0].c_str(), dynId);
494 return true;
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");
501 if (sysCmds != NULL)
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);
512 else
514 log.displayNL("Variable SystemCmd not found !");
517 return true;
521 //-----------------------------------------------
522 // 'mute'
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 )
529 return false;
531 sint32 delay = -1;
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());
549 else
551 nlwarning("(mute) No infos about the character %s",args[0].c_str());
554 return true;
556 } // mode //
560 //-----------------------------------------------
561 // 'remove'
563 //-----------------------------------------------
564 NLMISC_COMMAND(remove,"remove an entity from","<entity name>")
566 if( args.size() < 1 )
568 return false;
571 CCharacterInfos * charInfos = IOS->getCharInfos( args[0] );
572 if( charInfos )
574 IOS->removeEntity( charInfos->DataSetIndex);
576 else
578 nlwarning("<remove> Entity %s is not in the IOS",args[0].c_str());
579 return false;
581 return true;
586 NLMISC_COMMAND(genImpulsion,"generate a fake impulsion, used to debug the CActionGeneric on the FS","<nb_uint8>")
588 if( args.size() != 1 )
590 return false;
593 CEntityId id;
594 CMessage msgout( "IMPULSION_ID" );
595 msgout.serial( id );
597 CBitMemStream stream;
599 uint count;
600 NLMISC::fromString(args[0], count);
601 uint8 val = 0xAC;
602 for (uint i = 0; i < count; i++)
603 stream.serial (val);
605 //vector<uint8> &v = stream.bufferAsVector();
606 msgout.serialBufferWithSize ((uint8*)stream.buffer(), stream.length());
608 //const uint16 frontEndId = _Id.DynamicId;
609 sendMessageViaMirror ("FS", msgout);
611 return true;
616 NLMISC_COMMAND(display,"display","")
618 IOS->display(log);
619 return true;
622 NLMISC_COMMAND( displayChatClients, "Display the list of clients", "" )
624 IOS->getChatManager().displayChatClients(log);
625 return true;
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;
639 else
641 log.displayNL("syntax error: invalid parameter '%s'", params[0].c_str());
642 return false;
644 params.erase(params.begin());
647 IOS->getChatManager().displayChatGroups(log, displayUniverse, playerAudience);
648 return true;
651 NLMISC_COMMAND( displayChatAudience, "Display the current chat dynamic audience for a player, optionally, force the update", "<playerId> [update]" )
653 bool update = false;
654 if (args.size() < 1)
655 return false;
657 CEntityId eid = CEntityId(args[0]);
659 if (args.size() >= 2 && args[1] == "update")
660 update = true;
661 IOS->getChatManager().displayChatAudience(log, eid, update);
662 return true;
666 //-----------------------------------------------
667 // 'showChat'
669 //-----------------------------------------------
670 NLMISC_COMMAND(showChat,"show or hide chat messages","")
672 ShowChat = !ShowChat;
674 return true;
676 } // showChat //
679 NLMISC_COMMAND(chat, "send message chat", "<char_name> <chat_group> <message> [<id>]")
681 if (args.size() < 3)
682 return false;
684 CCharacterInfos *ci = IOS->getCharInfos(args[0]);
685 if (ci == NULL)
687 log.displayNL("ERR: Unknown %s", args[0].c_str());
688 return false;
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());
715 else
717 mode = CChatGroup::stringToGroupType(args[1]);
720 string chat_group = args[1];
721 ucstring ucstr;
722 ucstr.fromUtf8(args[2]);
723 TDataSetRow rowId = ci->DataSetIndex;
725 string rocketId = "";
726 if (args.size() > 3)
727 rocketId = args[3];
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();
734 if (mode != oldMode)
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);
750 if (oldMode != mode)
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);
756 else
757 IOS->getChatManager().getClient(rowId).setChatMode(oldMode);
760 catch(const Exception &e)
762 nlwarning("<cbChatMessage> %s",e.what());
765 return true;
768 NLMISC_COMMAND(farChat, "send far message chat", "<char_name> <chat_id> <message> [<id>]")
770 if (args.size() < 3)
771 return false;
773 uint32 id;
774 ucstring ucstr;
775 string rocketId = "";
777 string name = args[0];
778 ucstr.fromUtf8(args[2]);
779 if (args.size() > 3)
780 rocketId = args[3];
782 IOS->getChatManager().sendFarChat(name, ucstr, args[1], rocketId);
783 return true;
786 NLMISC_COMMAND(getRealName, "getRealName", "<char_name>")
788 if (args.size() != 1)
789 return false;
791 CCharacterInfos *ci = IOS->getCharInfos(args[0]);
792 if (ci == NULL)
794 log.displayNL("ERR: Unknown %s", args[0].c_str());
795 return true;
798 log.displayNL("%s", ci->ShortRealName.c_str());
800 return true;