Premium Sanchez 2464 Posted February 10, 2014 Premium Share Posted February 10, 2014 M2 Download Center This is the hidden content, please Sign In or Sign Up ( Internal ) Here ( Bonus - Unban Command ) Hi, In this thread I will show you how to do an in-game ban for your GMs. First of all, you need to make a new column in the account.account. The name of the field should be reason and select varchar as type. Or just use this in your console to create the field: ALTER TABLE account ADD reason VARCHAR(256); Now open game/cmd.cpp and search for this: ACMD(do_block_chat); Add this under that: ACMD(do_ban); Search for this still in the game/cmd.cpp: { "block_chat_list",do_block_chat_list, 0, POS_DEAD, GM_PLAYER }, Make a new line and add this under that: { "ban", do_ban, 0, POS_DEAD, GM_IMPLEMENTOR }, At this point you can change the rights for the command: GM_PLAYER - do NOT choose this! GM_LOW_WIZARD GM_WIZARD GM_HIGH_WIZARD GM_GOD GM_IMPLEMENTOR Search for this event in game/cmd_gm.cpp: ACMD(do_block_chat) Add this under that: ACMD(do_ban) Now time to add the complete code to ACMD(do_ban): // Args char arg1[256], arg2[256], arg3[256]; // Local variables const char* szName; const char* szReason; int iDuration; one_argument(two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2)), arg3, sizeof(arg3)); // Invalid syntax if (!*arg1 || !*arg2 || !*arg3) { ch->ChatPacket(CHAT_TYPE_INFO, "Invalid Syntax, usage: <player name> <time in hours> <reason> tip: don't use spaces in the reason, use _"); return; } szName = arg1; iDuration = atoi(arg2); szReason = arg3; if (iDuration <= 0) { ch->ChatPacket(CHAT_TYPE_INFO, "Duration can't be 0 or minus."); return; } LPCHARACTER tch = CHARACTER_MANAGER::instance().FindPC(szName); if (!tch) { ch->ChatPacket(CHAT_TYPE_INFO, "%s is not playing", szName); return; } if (!tch->GetDesc()) { ch->ChatPacket(CHAT_TYPE_INFO, "%s don't have desc", szName); return; } if (tch == ch) { ch->ChatPacket(CHAT_TYPE_INFO, "What's wrong with you? Don't ban yourself"); return; } if (tch->GetGMLevel() > GM_PLAYER) { ch->ChatPacket(CHAT_TYPE_INFO, "Do not ban GMs"); return; } std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("UPDATE account.account SET availDt = FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i), reason = '%s' WHERE id = %d", iDuration * 3600, szReason, tch->GetDesc()->GetAccountTable().id)); tch->GetDesc()->DelayedDisconnect(5); sys_log(0, "%s[%d] banned %s for %i hours with reason: %s", ch->GetName(), ch->GetPlayerID(), szName, iDuration, szReason); ch->ChatPacket(CHAT_TYPE_INFO, "%s has been banned for %i hours with reason: %s", szName, iDuration, szReason); Check how it works: Spoiler /ban <player name> <duration in hours> <reason> Example: /ban Doe 24 Hacking Quote Feb 10 03:30:15.890000 :: Sanchez[57735] banned Doe for 24 hours with reason: Hacking If you have any question or suggestion, please just reply to this topic. Kind Regards, Sanchez 15 1 1 4 56 Link to comment Share on other sites More sharing options...
Mehti 76 Posted February 10, 2014 Share Posted February 10, 2014 Very nice share friend. @Vanilla, maybe you want add this to vanilla core project 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted February 10, 2014 Author Premium Share Posted February 10, 2014 Thank you, hope you find it useful. 1 Link to comment Share on other sites More sharing options...
HITRON 694 Posted February 10, 2014 Share Posted February 10, 2014 Cool! 2 Link to comment Share on other sites More sharing options...
Padrio 987 Posted February 10, 2014 Share Posted February 10, 2014 Isnt the varchar max len only 255? Gesendet von meinem Nexus 5 mit Tapatalk 1 Link to comment Share on other sites More sharing options...
Rumor 2603 Posted February 10, 2014 Share Posted February 10, 2014 that's really nice, alot better than using custom ban reasons in the client and setting the word in status of account.account db 1 Link to comment Share on other sites More sharing options...
Denis 1474 Posted February 10, 2014 Share Posted February 10, 2014 It's really nice i was looking for something like this 2 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted February 10, 2014 Author Premium Share Posted February 10, 2014 Thanks for the replies. 1 Link to comment Share on other sites More sharing options...
Honorable Member xP3NG3Rx 19656 Posted February 10, 2014 Honorable Member Share Posted February 10, 2014 (edited) Edited August 21, 2022 by Metin2 Dev Core X - External 2 Internal 2 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted February 15, 2014 Author Premium Share Posted February 15, 2014 Hi guys, I made a small update, the first post has been edited with these changes: GMs now can't ban another GMs The banned user will be disconnected in 5 seconds 3 Link to comment Share on other sites More sharing options...
Sphinx² 24 Posted February 16, 2014 Share Posted February 16, 2014 Why you have this part in your code? if (!ch || ch->GetGMLevel() != GM_IMPLEMENTOR) // Again change here the rights { sys_log(0, "do_ban without rights %s[%d]", ch->GetName(), ch->GetPlayerID()); return; } The command interpreter is already checking the permissions. Kind regards Sphinx 4 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted February 16, 2014 Author Premium Share Posted February 16, 2014 I know, but I don't think its a bad idea to recheck again. 1 Link to comment Share on other sites More sharing options...
Sphinx² 24 Posted February 16, 2014 Share Posted February 16, 2014 I know, but I don't think its a bad idea to recheck again. The other functions of ymir dont recheck the permissions. But if you think you have more security with this check then use it. 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted February 16, 2014 Author Premium Share Posted February 16, 2014 Yes, I feel much better with this check. Maybe I'm a paranoid or something. 1 4 Link to comment Share on other sites More sharing options...
-TÜRK- 23 Posted February 16, 2014 Share Posted February 16, 2014 Yes, I feel much better with this check. Maybe I'm a paranoid or something. LMFAO 1 Link to comment Share on other sites More sharing options...
Mercury 5 Posted March 26, 2014 Share Posted March 26, 2014 Hi good morning, as I can make a second query? I want to enter data into a second table outside, for instance that "banlist" I may get a second query? how i can do? The second table contains the user id, user name, start date, end date and reason of the ban, it would be possible to do this? SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `banlist` -- ---------------------------- DROP TABLE IF EXISTS `banlist`; CREATE TABLE `banlist` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(24) CHARACTER SET ascii NOT NULL, `begins` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `finish` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `reason` varchar(256) CHARACTER SET ascii DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin5; -- ---------------------------- -- Records of banlist -- ---------------------------- INSERT INTO banlist VALUES ('1', 'Test', '2014-03-26 00:24:59', '0000-00-00 00:00:00', 'hack'); Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted March 26, 2014 Author Premium Share Posted March 26, 2014 Sure it's possible. I'm not tested, but here it is: DBManager::instance().DirectQuery("INSERT INTO account.banlist (id, name, begins, finish, reason) VALUES ('%d', %s, NOW(), FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i, %s)", LCHARACTER->GetAID(), LCHARACTER->GetName(), duration * 3600, reason); 1 Link to comment Share on other sites More sharing options...
Mercury 5 Posted March 26, 2014 Share Posted March 26, 2014 Sure it's possible. I'm not tested, but here it is: DBManager::instance().DirectQuery("INSERT INTO account.banlist (id, name, begins, finish, reason) VALUES ('%d', %s, NOW(), FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i, %s)", LCHARACTER->GetAID(), LCHARACTER->GetName(), duration * 3600, reason); I refer to include the two queries, which you already provided in the source + I need, you understand my idea? as might be included in the source without generating an error? I tried adding a new line but would not let me compile Thank you for your response sanchez. This generates an error when I compile. My knowledge c++ is very basic LCHARACTER = CHARACTER_MANAGER::instance().FindPC(name); std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("UPDATE account.account SET status = 'BLOCK', availDt = FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i), reason = '%s' WHERE id = %d", duration * 3600, reason, LCHARACTER->GetAID())); std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery("INSERT INTO account.banlist (id, name, begins, finish, reason) VALUES ('%d', %s, NOW(), FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i, %s)", LCHARACTER->GetAID(), LCHARACTER->GetName(), duration * 3600, reason); LDESC->DelayedDisconnect(5); Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted March 26, 2014 Author Premium Share Posted March 26, 2014 Rename the second msg to msg1 or to something else, but you don't need that. Just use this: DBManager::instance().DirectQuery("INSERT INTO account.banlist (id, name, begins, finish, reason) VALUES ('%d', %s, NOW(), FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i, %s)", LCHARACTER->GetAID(), LCHARACTER->GetName(), duration * 3600, reason); 2 Link to comment Share on other sites More sharing options...
Mercury 5 Posted March 26, 2014 Share Posted March 26, 2014 Rename the second msg to msg1 or to something else, but you don't need that. Just use this: DBManager::instance().DirectQuery("INSERT INTO account.banlist (id, name, begins, finish, reason) VALUES ('%d', %s, NOW(), FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i, %s)", LCHARACTER->GetAID(), LCHARACTER->GetName(), duration * 3600, reason); I know it is unnecessary, the second query is to enter data into a table outside account, to have a ban list on the website, you understand? That thinking we will not ban users every second can be a little "extra" work to game, I do not suppose a large consumption, I'm wrong? Thank you very much for your answers Sanchez hope to return the favor. 1 Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted March 26, 2014 Author Premium Share Posted March 26, 2014 Sorry, but I don't understand you. What is the problem or what? 1 Link to comment Share on other sites More sharing options...
Mercury 5 Posted March 27, 2014 Share Posted March 27, 2014 Sorry, but I don't understand you. What is the problem or what? Sorry my bad english, no problem Sanchez, everything is perfect thank you very much for your advice! a hug Link to comment Share on other sites More sharing options...
Avertus 1 Posted July 5, 2014 Share Posted July 5, 2014 I have problem with query. Syslog: http://wklej.to/AkvfE Can you help? I have reason i account.account. Link to comment Share on other sites More sharing options...
Premium Sanchez 2464 Posted July 5, 2014 Author Premium Share Posted July 5, 2014 Try this: "UPDATE account.account SET status = 'BLOCK', availDt = 'FROM_UNIXTIME(UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) + %i)', reason = '%s' WHERE id = '%d'" Link to comment Share on other sites More sharing options...
Avertus 1 Posted July 5, 2014 Share Posted July 5, 2014 Nope http://wklej.to/hlGuu :C Link to comment Share on other sites More sharing options...
Recommended Posts