|
1 | 1 | // SETUP |
2 | | - |
| 2 | +/* OLD |
3 | 3 | /proc/TopicHandlers() |
4 | 4 | . = list() |
5 | 5 | var/list/all_handlers = subtypesof(/datum/world_topic) |
|
316 | 316 |
|
317 | 317 | message_admins(span_adminnotice("Incoming cross-sector newscaster article by [author_key] in channel [channel_name].")) |
318 | 318 | GLOB.news_network.submit_article(msg, author, channel_name) |
| 319 | +*/ |
| 320 | + |
| 321 | + |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | +/datum/world_topic |
| 326 | + /// query key |
| 327 | + var/key |
| 328 | + |
| 329 | + /// can be used with anonymous authentication |
| 330 | + var/anonymous = FALSE |
| 331 | + |
| 332 | + var/list/required_params = list() |
| 333 | + var/statuscode |
| 334 | + var/response |
| 335 | + var/data |
| 336 | + |
| 337 | +/datum/world_topic/proc/CheckParams(list/params) |
| 338 | + var/list/missing_params = list() |
| 339 | + var/errorcount = 0 |
| 340 | + |
| 341 | + for(var/param in required_params) |
| 342 | + if(!params[param]) |
| 343 | + errorcount++ |
| 344 | + missing_params += param |
| 345 | + |
| 346 | + if(errorcount) |
| 347 | + statuscode = 400 |
| 348 | + response = "Bad Request - Missing parameters" |
| 349 | + data = missing_params |
| 350 | + return errorcount |
| 351 | + |
| 352 | +/datum/world_topic/proc/Run(list/input) |
| 353 | + // Always returns true; actual details in statuscode, response and data variables |
| 354 | + return TRUE |
| 355 | + |
| 356 | +// API INFO TOPICS |
| 357 | + |
| 358 | +/datum/world_topic/api_get_authed_functions |
| 359 | + key = "api_get_authed_functions" |
| 360 | + anonymous = TRUE |
| 361 | + |
| 362 | +/datum/world_topic/api_get_authed_functions/Run(list/input) |
| 363 | + . = ..() |
| 364 | + var/list/functions = GLOB.topic_tokens[input["auth"]] |
| 365 | + if(functions) |
| 366 | + statuscode = 200 |
| 367 | + response = "Authorized functions retrieved" |
| 368 | + data = functions |
| 369 | + else |
| 370 | + statuscode = 401 |
| 371 | + response = "Unauthorized - No functions found" |
| 372 | + data = null |
| 373 | + |
| 374 | +// TOPICS |
| 375 | + |
| 376 | +// If you modify the protocol for this, update tools/Tgstation.PRAnnouncer |
| 377 | +/datum/world_topic/pr_announce |
| 378 | + key = "announce" |
| 379 | + anonymous = TRUE |
| 380 | + var/static/list/PRcounts = list() //PR id -> number of times announced this round |
| 381 | + |
| 382 | +/datum/world_topic/pr_announce/Run(list/input) |
| 383 | + . = ..() |
| 384 | + var/list/payload = json_decode(input["payload"]) |
| 385 | + var/id = "[payload["pull_request"]["id"]]" |
| 386 | + if(!PRcounts[id]) |
| 387 | + PRcounts[id] = 1 |
| 388 | + else |
| 389 | + ++PRcounts[id] |
| 390 | + if(PRcounts[id] > CONFIG_GET(number/pr_announcements_per_round)) |
| 391 | + return |
| 392 | + |
| 393 | + var/final_composed = span_announce("PR: [input[key]]") |
| 394 | + for(var/client/C in GLOB.clients) |
| 395 | + C.AnnouncePR(final_composed) |
| 396 | + |
| 397 | + statuscode = 200 |
| 398 | + response = "Received" |
| 399 | + |
| 400 | +/datum/world_topic/ping |
| 401 | + key = "ping" |
| 402 | + anonymous = TRUE |
| 403 | + |
| 404 | +/datum/world_topic/ping/Run(list/input) |
| 405 | + . = ..() |
| 406 | + statuscode = 200 |
| 407 | + response = "Pong!" |
| 408 | + data = length(GLOB.clients) |
| 409 | + |
| 410 | +/datum/world_topic/status |
| 411 | + key = "status" |
| 412 | + anonymous = TRUE |
| 413 | + |
| 414 | +/datum/world_topic/status/Run(list/input) |
| 415 | + . = ..() |
| 416 | + |
| 417 | + data = list() |
| 418 | + |
| 419 | + data["version"] = GLOB.game_version |
| 420 | + data["respawn"] = config ? !!CONFIG_GET(flag/allow_respawn) : FALSE // show respawn as true regardless of "respawn as char" or "free respawn" |
| 421 | + data["enter"] = !LAZYACCESS(SSlag_switch.measures, DISABLE_NON_OBSJOBS) |
| 422 | + data["ai"] = CONFIG_GET(flag/allow_ai) |
| 423 | + data["host"] = world.host ? world.host : null |
| 424 | + |
| 425 | + data["round_id"] = GLOB.round_id |
| 426 | + |
| 427 | + data["map_name"] = SSmapping.current_map?.map_name || "Loading..." |
| 428 | + |
| 429 | + data["players"] = length(GLOB.clients) |
| 430 | + |
| 431 | + data["identifier"] = CONFIG_GET(string/serversqlname) |
| 432 | + |
| 433 | + |
| 434 | + var/public_address = CONFIG_GET(string/public_address) |
| 435 | + if(public_address) |
| 436 | + data["public_address"] = public_address |
| 437 | + |
| 438 | + data["revision"] = GLOB.revdata.commit |
| 439 | + data["revision_date"] = GLOB.revdata.date |
| 440 | + data["hub"] = GLOB.hub_visibility |
| 441 | + |
| 442 | + data["security_level"] = SSsecurity_level.get_current_level_as_text() |
| 443 | + data["round_duration"] = SSticker ? round((world.time-SSticker.round_start_time)/10) : 0 |
| 444 | + |
| 445 | + //Time dilation stats. |
| 446 | + data["time_dilation_current"] = SStime_track.time_dilation_current |
| 447 | + data["time_dilation_avg"] = SStime_track.time_dilation_avg |
| 448 | + data["time_dilation_avg_slow"] = SStime_track.time_dilation_avg_slow |
| 449 | + data["time_dilation_avg_fast"] = SStime_track.time_dilation_avg_fast |
| 450 | + |
| 451 | + data["soft_popcap"] = CONFIG_GET(number/soft_popcap) || 0 |
| 452 | + data["hard_popcap"] = CONFIG_GET(number/hard_popcap) || 0 |
| 453 | + data["extreme_popcap"] = CONFIG_GET(number/extreme_popcap) || 0 |
| 454 | + data["popcap"] = max(CONFIG_GET(number/soft_popcap), CONFIG_GET(number/hard_popcap), CONFIG_GET(number/extreme_popcap)) //generalized field for this concept for use across ss13 codebases |
| 455 | + data["bunkered"] = CONFIG_GET(flag/panic_bunker) || FALSE |
| 456 | + data["interviews"] = CONFIG_GET(flag/panic_bunker_interview) || FALSE |
| 457 | + if(SSshuttle?.emergency) |
| 458 | + data["shuttle_mode"] = SSshuttle.emergency.mode |
| 459 | + // Shuttle status, see /__DEFINES/stat.dm |
| 460 | + data["shuttle_timer"] = SSshuttle.emergency.timeLeft() |
| 461 | + // Shuttle timer, in seconds |
| 462 | + |
| 463 | + statuscode = 200 |
| 464 | + response = "Status retrieved" |
| 465 | + |
| 466 | +/datum/world_topic/status/authed |
| 467 | + key = "status_authed" |
| 468 | + anonymous = FALSE |
| 469 | + |
| 470 | +/datum/world_topic/status/authed/Run(list/input) |
| 471 | + . = ..() |
| 472 | + |
| 473 | + var/list/adm = get_admin_counts() |
| 474 | + var/list/presentmins = adm["present"] |
| 475 | + var/list/afkmins = adm["afk"] |
| 476 | + data["admins"] = length(presentmins) + length(afkmins) |
| 477 | + data["gamestate"] = SSticker.current_state |
| 478 | + |
| 479 | + data["active_players"] = get_active_player_count() |
| 480 | + |
| 481 | + data["mcpu"] = world.map_cpu |
| 482 | + data["cpu"] = world.cpu |
| 483 | + |
| 484 | +GLOBAL_LIST_EMPTY(bot_event_sending_que) |
| 485 | +GLOBAL_LIST_EMPTY(bot_ooc_sending_que) |
| 486 | +GLOBAL_LIST_EMPTY(bot_asay_sending_que) |
| 487 | + |
| 488 | +/datum/world_topic/receive_info |
| 489 | + key = "receive_info" |
| 490 | + |
| 491 | +/datum/world_topic/receive_info/Run(list/input) |
| 492 | + data = list() |
| 493 | + if(!length(GLOB.bot_event_sending_que) && !length(GLOB.bot_ooc_sending_que) && !length(GLOB.bot_asay_sending_que)) |
| 494 | + statuscode = 501 |
| 495 | + response = "No events pool." |
| 496 | + return |
| 497 | + |
| 498 | + //Yeah, we can use /datum/http_request, but nuh... it's less fun. |
| 499 | + data["events"] = GLOB.bot_event_sending_que |
| 500 | + data["ooc"] = GLOB.bot_ooc_sending_que |
| 501 | + data["admin"] = GLOB.bot_asay_sending_que |
| 502 | + GLOB.bot_event_sending_que = list() |
| 503 | + GLOB.bot_ooc_sending_que = list() |
| 504 | + GLOB.bot_asay_sending_que = list() |
| 505 | + statuscode = 200 |
| 506 | + response = "Events sent." |
| 507 | + |
| 508 | +/datum/world_topic/send_info |
| 509 | + key = "send_info" |
| 510 | + required_params = list("data") |
| 511 | + |
| 512 | +/datum/world_topic/send_info/Run(list/input) |
| 513 | + data = list() |
| 514 | + |
| 515 | + var/list/bot_data = input["data"] |
| 516 | + if(!istype(bot_data) || !length(bot_data)) |
| 517 | + statuscode = 403 |
| 518 | + response = "Wrong data" |
| 519 | + return |
| 520 | + |
| 521 | + if(bot_data["ooc"]) |
| 522 | + for(var/list/data in bot_data["ooc"]) |
| 523 | + var/msg = sanitize(data["message"]) |
| 524 | + for(var/client/C in GLOB.clients) |
| 525 | + if(C.prefs.chat_toggles & CHAT_OOC) |
| 526 | + to_chat(C, "<span class='ooc'><span class='prefix'>DISCORD OOC:</span> <EM>[data["author"]]:</EM> <span class='message linkify'>[msg]</span></span>") |
| 527 | + |
| 528 | + if(bot_data["admin"]) |
| 529 | + for(var/list/data in bot_data["admin"]) |
| 530 | + to_chat(GLOB.admins, "<span class='adminsay'><span class='prefix'>DISCORD ADMIN:</span> <EM>[data["author"]]</EM>: <span class='message linkify'>[sanitize(data["message"])]</span></span>", confidential = TRUE) |
| 531 | + |
| 532 | + statuscode = 200 |
| 533 | + response = "Events received." |
| 534 | + |
| 535 | +/datum/world_topic/delay |
| 536 | + key = "set_delay" |
| 537 | + required_params = list("delay") |
| 538 | + |
| 539 | +/datum/world_topic/delay/Run(list/input) |
| 540 | + . = ..() |
| 541 | + |
| 542 | + if(SSticker.timeLeft < 0 && input["delay"]) |
| 543 | + statuscode = 501 |
| 544 | + response = "Delay already set to same state." |
| 545 | + return |
| 546 | + |
| 547 | + SSticker.timeLeft = input["delay"] ? -1 : 300 |
| 548 | + message_admins(span_notice("[input["source"]] ([input["addr"]]) [SSticker.timeLeft < 0 ? "delayed the round start" : "has made the round start normally"].")) |
| 549 | + to_chat(world, span_notice("The game start has been [SSticker.timeLeft < 0 ? "delayed" : "continued"].")) |
| 550 | + if(SSticker.timeLeft < 0) |
| 551 | + statuscode = 200 |
| 552 | + response = "Delay set." |
| 553 | + else |
| 554 | + statuscode = 200 |
| 555 | + response = "Delay removed." |
0 commit comments