Skip to content

Commit

Permalink
Привязка Discord-аккаунта
Browse files Browse the repository at this point in the history
Работает через SS220Bot'а
upd 3.01: Обновление под Async SQL
  • Loading branch information
RV666 committed Jan 27, 2021
1 parent 18c1ebc commit 948dd69
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ CREATE TABLE `player` (
`fupdate` smallint(4) DEFAULT '0',
`parallax` tinyint(1) DEFAULT '8',
`byond_date` DATE DEFAULT NULL,
`discord_id` varchar(32) NULL DEFAULT NULL,
`discord_name` varchar(32) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ckey` (`ckey`),
KEY `lastseen` (`lastseen`),
Expand Down
2 changes: 2 additions & 0 deletions SQL/paradise_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ CREATE TABLE `SS13_player` (
`fupdate` smallint(4) DEFAULT '0',
`parallax` tinyint(1) DEFAULT '8',
`byond_date` DATE DEFAULT NULL,
`discord_id` varchar(32) NULL DEFAULT NULL,
`discord_name` varchar(32) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ckey` (`ckey`),
KEY `lastseen` (`lastseen`),
Expand Down
4 changes: 4 additions & 0 deletions SQL/updates/discord_link.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Updating the SQL for Discord account linking
#Adding new columns to contain the Discord account ID and Name values.
ALTER TABLE `player` ADD `discord_id` varchar(32) DEFAULT NULL AFTER `byond_date`;
ALTER TABLE `player` ADD `discord_name` varchar(32) DEFAULT NULL AFTER `discord_id`;
5 changes: 5 additions & 0 deletions code/modules/admin/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ GLOBAL_VAR_INIT(nologevent, 0)
body += "[admin_jump_link(M)]\] </b><br>"
body += "<b>Mob type:</b> [M.type]<br>"
if(M.client)
if(M.client.prefs.discord_id)
if(length(M.client.prefs.discord_id) < 32)
body += "<b>Discord:</b> <@[M.client.prefs.discord_id]> <b>[M.client.prefs.discord_name]</b><br>"
else
body += "<b>Discord: Привязка не завершена!</b><br>"
if(M.client.related_accounts_cid.len)
body += "<b>Related accounts by CID:</b> [jointext(M.client.related_accounts_cid, " - ")]<br>"
if(M.client.related_accounts_ip.len)
Expand Down
28 changes: 28 additions & 0 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,34 @@
set hidden = 1
fit_viewport()

/client/verb/link_discord_account()
set name = "Привязка Discord"
set category = "Special Verbs"
set desc = "Привязать аккаунт Discord для удобного просмотра игровой статистики на нашем Discord-сервере."

if(!config.discordurl)
return
if(IsGuestKey(key))
to_chat(usr, "Гостевой аккаунт не может быть связан.")
return
if(prefs)
prefs.load_preferences(usr)
if(prefs && prefs.discord_id && length(prefs.discord_id) < 32)
to_chat(usr, "<span class='darkmblue'>Аккаунт Discord уже привязан! Чтобы отвязать используйте команду <span class='boldannounce'>!отвязать_аккаунт</span> на Discord-сервере.</span>")
return
var/token = md5("[world.time+rand(1000,1000000)]")
if(SSdbcore.IsConnected())
var/datum/db_query/query_update_token = SSdbcore.NewQuery("UPDATE [format_table_name("player")] SET discord_id=:token WHERE ckey =:ckey", list("token" = token, "ckey" = ckey))
if(!query_update_token.warn_execute())
to_chat(usr, "<span class='warning'>Ошибка записи токена в БД! Обратитесь к администрации.</span>")
log_debug("link_discord_account: failed db update discord_id for ckey [ckey]")
qdel(query_update_token)
return
qdel(query_update_token)
to_chat(usr, "<span class='darkmblue'>Для завершения используйте команду <span class='boldannounce'>!привязать_аккаунт [token]</span> на Discord-сервере!</span>")
if(prefs)
prefs.load_preferences(usr)

/client/verb/resend_ui_resources()
set name = "Reload UI Resources"
set desc = "Reload your UI assets if they are not working"
Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/preference/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
// Parallax
var/parallax = PARALLAX_HIGH

var/discord_id = null
var/discord_name = null

/datum/preferences/New(client/C)
parent = C
b_type = pick(4;"O-", 36;"O+", 3;"A-", 28;"A+", 1;"B-", 20;"B+", 1;"AB-", 5;"AB+")
Expand Down
8 changes: 7 additions & 1 deletion code/modules/client/preference/preferences_mysql.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
clientfps,
atklog,
fuid,
parallax
parallax,
discord_id,
discord_name
FROM [format_table_name("player")]
WHERE ckey=:ckey"}, list(
"ckey" = C.ckey
Expand Down Expand Up @@ -45,6 +47,8 @@
atklog = text2num(query.item[14])
fuid = text2num(query.item[15])
parallax = text2num(query.item[16])
discord_id = query.item[17]
discord_name = query.item[18]

qdel(query)

Expand All @@ -64,6 +68,8 @@
atklog = sanitize_integer(atklog, 0, 100, initial(atklog))
fuid = sanitize_integer(fuid, 0, 10000000, initial(fuid))
parallax = sanitize_integer(parallax, 0, 16, initial(parallax))
discord_id = sanitize_text(discord_id, initial(discord_id))
discord_name = sanitize_text(discord_name, initial(discord_name))
return 1

/datum/preferences/proc/save_preferences(client/C)
Expand Down

0 comments on commit 948dd69

Please sign in to comment.