-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathnew_player.dm
538 lines (462 loc) · 20.3 KB
/
new_player.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#define LINKIFY_READY(string, value) "<a href='byond://?src=[REF(src)];ready=[value]'>[string]</a>"
///Cooldown for the Reset Lobby Menu HUD verb
#define RESET_HUD_INTERVAL 15 SECONDS
/mob/dead/new_player
flags_1 = NONE
invisibility = INVISIBILITY_ABSTRACT
density = FALSE
stat = DEAD
var/ready = FALSE
/// Referenced when you want to delete the new_player later on in the code.
var/spawning = FALSE
/// For instant transfer once the round is set up
var/mob/living/new_character
///Used to make sure someone doesn't get spammed with messages if they're ineligible for roles.
var/ineligible_for_roles = FALSE
/// Used to track if the player's jobs menu sent a message saying it successfully mounted.
var/jobs_menu_mounted = FALSE
///Cooldown for the Reset Lobby Menu HUD verb
COOLDOWN_DECLARE(reset_hud_cooldown)
/mob/dead/new_player/Initialize(mapload)
if(client && SSticker.state == GAME_STATE_STARTUP)
var/atom/movable/screen/splash/S = new(null, client, TRUE)
S.Fade(TRUE)
if(length(GLOB.newplayer_start))
forceMove(pick(GLOB.newplayer_start))
else
forceMove(locate(1,1,1))
. = ..()
GLOB.new_player_list += src
add_verb(usr, /datum/latejoin_menu/verb/open_fallback_ui)
/mob/dead/new_player/Destroy()
GLOB.new_player_list -= src
return ..()
/mob/dead/new_player/prepare_huds()
return
/mob/dead/new_player/proc/new_player_panel()
var/datum/asset/asset_datum = get_asset_datum(/datum/asset/simple/lobby)
asset_datum.send(client)
var/output = "<center><p><a href='byond://?src=[REF(src)];show_preferences=1'>Setup Character</a></p>"
output += "<center><p><a href='byond://?src=[REF(src)];show_gameoptions=1'>Game Options</a></p>"
if(SSticker.current_state <= GAME_STATE_PREGAME)
switch(ready)
if(PLAYER_NOT_READY)
output += "<p>\[ [LINKIFY_READY("Ready", PLAYER_READY_TO_PLAY)] | <b>Not Ready</b> | [LINKIFY_READY("Observe", PLAYER_READY_TO_OBSERVE)] \]</p>"
if(PLAYER_READY_TO_PLAY)
output += "<p>\[ <b>Ready</b> | [LINKIFY_READY("Not Ready", PLAYER_NOT_READY)] | [LINKIFY_READY("Observe", PLAYER_READY_TO_OBSERVE)] \]</p>"
if(PLAYER_READY_TO_OBSERVE)
output += "<p>\[ [LINKIFY_READY("Ready", PLAYER_READY_TO_PLAY)] | [LINKIFY_READY("Not Ready", PLAYER_NOT_READY)] | <b> Observe </b> \]</p>"
else
output += "<p><a href='byond://?src=[REF(src)];manifest=1'>View the Crew Manifest</a></p>"
output += "<p><a href='byond://?src=[REF(src)];late_join=1'>Join Game!</a></p>"
output += "<p>[LINKIFY_READY("Observe", PLAYER_READY_TO_OBSERVE)]</p>"
if(!IsGuestKey(src.key))
if (SSdbcore.Connect())
var/isadmin = 0
if(src.client && src.client.holder)
isadmin = 1
var/datum/DBQuery/query_get_new_polls = SSdbcore.NewQuery({"
SELECT id FROM [format_table_name("poll_question")]
WHERE (adminonly = 0 OR :isadmin = 1)
AND Now() BETWEEN starttime AND endtime
AND id NOT IN (
SELECT pollid FROM [format_table_name("poll_vote")]
WHERE ckey = :ckey
)
AND id NOT IN (
SELECT pollid FROM [format_table_name("poll_textreply")]
WHERE ckey = :ckey
)
"}, list("isadmin" = isadmin, "ckey" = ckey))
var/rs = REF(src)
if(query_get_new_polls.Execute())
var/newpoll = 0
if(query_get_new_polls.NextRow())
newpoll = 1
if(newpoll)
output += "<p><b><a href='byond://?src=[rs];showpoll=1'>Show Player Polls</A> (NEW!)</b></p>"
else
output += "<p><a href='byond://?src=[rs];showpoll=1'>Show Player Polls</A></p>"
qdel(query_get_new_polls)
if(QDELETED(src))
return
output += "</center>"
var/datum/browser/popup = new(src, "playersetup", "<div align='center'>New Player Options</div>", 250, 265)
popup.set_window_options("can_close=0")
popup.set_content(output)
popup.open(FALSE)
// List of possible actions user has chosen on the New Players menus
/mob/dead/new_player/Topic(href, href_list[])
if(src != usr)
return 0
if(!client)
return 0
//Determines Relevent Population Cap
var/relevant_cap
var/hpc = CONFIG_GET(number/hard_popcap)
var/epc = CONFIG_GET(number/extreme_popcap)
if(hpc && epc)
relevant_cap = min(hpc, epc)
else
relevant_cap = max(hpc, epc)
if(href_list["show_preferences"])
if(!SSquirks.initialized)
to_chat(usr, span_notice("The game is still loading. Please wait a bit before editing your character."))
return
var/datum/preferences/preferences = client.prefs
preferences.current_window = PREFERENCE_TAB_CHARACTER_PREFERENCES
preferences.update_static_data(usr)
preferences.ui_interact(usr)
return TRUE
if(href_list["show_gameoptions"])
var/datum/preferences/preferences = client.prefs
preferences.current_window = PREFERENCE_TAB_GAME_PREFERENCES
preferences.update_static_data(usr)
preferences.ui_interact(usr)
return TRUE
if(href_list["ready"])
var/tready = text2num(href_list["ready"])
//Avoid updating ready if we're after PREGAME (they should use latejoin instead)
//This is likely not an actual issue but I don't have time to prove that this
//no longer is required
if(SSticker.current_state <= GAME_STATE_PREGAME)
ready = tready
//if it's post initialisation and they're trying to observe we do the needful
if(!SSticker.current_state < GAME_STATE_PREGAME && tready == PLAYER_READY_TO_OBSERVE)
ready = tready
make_me_an_observer()
return
if(href_list["refresh"])
src << browse(null, "window=playersetup") //closes the player setup window
new_player_panel()
if(href_list["late_join"])
if(!SSticker || !SSticker.IsRoundInProgress())
to_chat(usr, span_danger("The round is either not ready, or has already finished..."))
return
if(SSticker.queued_players.len || (relevant_cap && living_player_count() >= relevant_cap && !(ckey(key) in GLOB.permissions.admin_datums)))
//yogs start -- donors bypassing the queue
if(ckey(key) in get_donators())
to_chat(usr, span_notice("Because you are a donator, you have bypassed the queue! Thank you for donating!"))
GLOB.latejoin_menu.ui_interact(src)
return
//yogs end
to_chat(usr, span_danger("[CONFIG_GET(string/hard_popcap_message)]"))
var/queue_position = SSticker.queued_players.Find(usr)
if(queue_position == 1)
to_chat(usr, span_notice("You are next in line to join the game. You will be notified when a slot opens up."))
else if(queue_position)
to_chat(usr, span_notice("There are [queue_position-1] players in front of you in the queue to join the game."))
else
SSticker.queued_players += usr
to_chat(usr, span_notice("You have been added to the queue to join the game. Your position in queue is [SSticker.queued_players.len]."))
return
GLOB.latejoin_menu.ui_interact(usr)
if(href_list["manifest"])
ViewManifest()
else if(!href_list["late_join"])
new_player_panel()
if(href_list["showpoll"])
handle_player_polling()
return
if(href_list["pollid"])
var/pollid = href_list["pollid"]
if(istext(pollid))
pollid = text2num(pollid)
if(isnum(pollid) && ISINTEGER(pollid))
src.poll_player(pollid)
return
if(href_list["votepollid"] && href_list["votetype"])
var/pollid = text2num(href_list["votepollid"])
var/votetype = href_list["votetype"]
//lets take data from the user to decide what kind of poll this is, without validating it
//what could go wrong
switch(votetype)
if(POLLTYPE_OPTION)
var/optionid = text2num(href_list["voteoptionid"])
if(vote_on_poll(pollid, optionid))
to_chat(usr, span_notice("Vote successful."))
else
to_chat(usr, span_danger("Vote failed, please try again or contact an administrator."))
if(POLLTYPE_TEXT)
var/replytext = href_list["replytext"]
if(log_text_poll_reply(pollid, replytext))
to_chat(usr, span_notice("Feedback logging successful."))
else
to_chat(usr, span_danger("Feedback logging failed, please try again or contact an administrator."))
if(POLLTYPE_RATING)
var/id_min = text2num(href_list["minid"])
var/id_max = text2num(href_list["maxid"])
if( (id_max - id_min) > 100 ) //Basic exploit prevention
//(protip, this stops no exploits)
to_chat(usr, "The option ID difference is too big. Please contact administration or the database admin.")
return
for(var/optionid = id_min; optionid <= id_max; optionid++)
if(!isnull(href_list["o[optionid]"])) //Test if this optionid was replied to
var/rating
if(href_list["o[optionid]"] == "abstain")
rating = null
else
rating = text2num(href_list["o[optionid]"])
if(!isnum(rating) || !ISINTEGER(rating))
return
if(!vote_on_numval_poll(pollid, optionid, rating))
to_chat(usr, span_danger("Vote failed, please try again or contact an administrator."))
return
to_chat(usr, span_notice("Vote successful."))
if(POLLTYPE_MULTI)
var/id_min = text2num(href_list["minoptionid"])
var/id_max = text2num(href_list["maxoptionid"])
if( (id_max - id_min) > 100 ) //Basic exploit prevention
to_chat(usr, "The option ID difference is too big. Please contact administration or the database admin.")
return
for(var/optionid = id_min; optionid <= id_max; optionid++)
if(!isnull(href_list["option_[optionid]"])) //Test if this optionid was selected
var/i = vote_on_multi_poll(pollid, optionid)
switch(i)
if(0)
continue
if(1)
to_chat(usr, span_danger("Vote failed, please try again or contact an administrator."))
return
if(2)
to_chat(usr, span_danger("Maximum replies reached."))
break
to_chat(usr, span_notice("Vote successful."))
if(POLLTYPE_IRV)
if (!href_list["IRVdata"])
to_chat(src, span_danger("No ordering data found. Please try again or contact an administrator."))
return
var/list/votelist = splittext(href_list["IRVdata"], ",")
if (!vote_on_irv_poll(pollid, votelist))
to_chat(src, span_danger("Vote failed, please try again or contact an administrator."))
return
to_chat(src, span_notice("Vote successful."))
//When you cop out of the round (NB: this HAS A SLEEP FOR PLAYER INPUT IN IT)
/mob/dead/new_player/proc/make_me_an_observer()
if(QDELETED(src) || !src.client)
ready = PLAYER_NOT_READY
return FALSE
var/this_is_like_playing_right = tgui_alert(usr, "Are you sure you wish to observe? You will not be able to play this round!","Player Setup",list("Yes","No"))
if(QDELETED(src) || !src.client || this_is_like_playing_right != "Yes")
ready = PLAYER_NOT_READY
src << browse(null, "window=playersetup") //closes the player setup window
new_player_panel()
return FALSE
var/mob/dead/observer/observer = new()
spawning = TRUE
observer.started_as_observer = TRUE
close_spawn_windows()
var/obj/effect/landmark/observer_start/O = locate(/obj/effect/landmark/observer_start) in GLOB.landmarks_list
to_chat(src, span_notice("Now teleporting."))
if (O)
observer.forceMove(O.loc)
else
to_chat(src, span_notice("Teleporting failed. Ahelp an admin please"))
stack_trace("There's no freaking observer landmark available on this map or you're making observers before the map is initialised")
observer.key = key
observer.client = client
observer.set_ghost_appearance()
if(observer.client && observer.client.prefs)
observer.real_name = observer.client.prefs.read_preference(/datum/preference/name/real_name)
observer.name = observer.real_name
observer.client.init_verbs()
observer.update_appearance(UPDATE_ICON)
observer.stop_sound_channel(CHANNEL_LOBBYMUSIC)
QDEL_NULL(mind)
qdel(src)
return TRUE
/proc/get_job_unavailable_error_message(retval, jobtitle)
switch(retval)
if(JOB_AVAILABLE)
return "[jobtitle] is available."
if(JOB_UNAVAILABLE_GENERIC)
return "[jobtitle] is unavailable."
if(JOB_UNAVAILABLE_BANNED)
return "You are currently banned from [jobtitle]."
if(JOB_UNAVAILABLE_PLAYTIME)
return "You do not have enough relevant playtime for [jobtitle]."
if(JOB_UNAVAILABLE_ACCOUNTAGE)
return "Your account is not old enough for [jobtitle]."
if(JOB_UNAVAILABLE_SLOTFULL)
return "[jobtitle] is already filled to capacity."
return GENERIC_JOB_UNAVAILABLE_ERROR
/mob/dead/new_player/proc/IsJobUnavailable(rank, latejoin = FALSE)
var/datum/job/job = SSjob.GetJob(rank)
if(!job)
return JOB_UNAVAILABLE_GENERIC
if((job.current_positions >= job.total_positions) && job.total_positions != -1)
if(job.title == "Assistant")
if(isnum(client.player_age) && client.player_age <= 14) //Newbies can always be assistants
return JOB_AVAILABLE
for(var/datum/job/J in SSjob.occupations)
if(J && J.current_positions < J.total_positions && J.title != job.title)
return JOB_UNAVAILABLE_SLOTFULL
else
return JOB_UNAVAILABLE_SLOTFULL
if(is_banned_from(ckey, rank))
return JOB_UNAVAILABLE_BANNED
if(QDELETED(src))
return JOB_UNAVAILABLE_GENERIC
if(!job.player_old_enough(client))
return JOB_UNAVAILABLE_ACCOUNTAGE
if(job.required_playtime_remaining(client))
return JOB_UNAVAILABLE_PLAYTIME
if(latejoin && !job.special_check_latejoin(client))
return JOB_UNAVAILABLE_GENERIC
return JOB_AVAILABLE
/mob/dead/new_player/proc/AttemptLateSpawn(rank)
var/error = IsJobUnavailable(rank)
if(error != JOB_AVAILABLE)
tgui_alert(usr, get_job_unavailable_error_message(error, rank))
return FALSE
if(SSticker.late_join_disabled)
tgui_alert(usr, "An administrator has disabled late join spawning.")
return FALSE
if(SSshuttle.arrivals)
close_spawn_windows() //In case we get held up
if(SSshuttle.arrivals.damaged && CONFIG_GET(flag/arrivals_shuttle_require_safe_latejoin))
src << tgui_alert(usr,"The arrivals shuttle is currently malfunctioning! You cannot join.")
return FALSE
if(CONFIG_GET(flag/arrivals_shuttle_require_undocked))
SSshuttle.arrivals.RequireUndocked(src)
//Remove the player from the join queue if he was in one and reset the timer
SSticker.queued_players -= src
SSticker.queue_delay = 4
var/datum/job/job = SSjob.GetJob(rank)
if(!SSjob.AssignRole(src, rank, TRUE))
tgui_alert(usr, "There was an unexpected error putting you into your requested job. If you cannot join with any job, you should contact an admin.")
return FALSE
var/mob/living/character = create_character(TRUE) //creates the human and transfers vars and mind
character.mind.quiet_round = character.client.prefs.read_preference(/datum/preference/toggle/quiet_mode) // yogs - Donor Features
var/equip = SSjob.EquipRank(character, rank, TRUE)
job.after_latejoin_spawn(character)
if(isliving(equip)) //Borgs get borged in the equip, so we need to make sure we handle the new mob.
character = equip
if(job && !job.override_latejoin_spawn(character))
SSjob.SendToLateJoin(character)
SSticker.minds += character.mind
character.client.init_verbs() // init verbs for the late join
var/mob/living/carbon/human/humanc
if(ishuman(character))
humanc = character //Let's retypecast the var to be human,
if(humanc) //These procs all expect humans
GLOB.data_core.manifest_inject(humanc)
if(SSshuttle.arrivals)
SSshuttle.arrivals.QueueAnnounce(humanc, rank)
else
AnnounceArrival(humanc, rank)
if(GLOB.highlander)
to_chat(humanc, span_userdanger("<i>THERE CAN BE ONLY ONE!!!</i>"))
humanc.make_scottish()
humanc.increment_scar_slot()
humanc.load_persistent_scars()
if(GLOB.curse_of_madness_triggered)
give_madness(humanc, GLOB.curse_of_madness_triggered)
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_CREWMEMBER_JOINED, humanc, rank)
GLOB.joined_player_list += character.ckey
if(CONFIG_GET(flag/allow_latejoin_antagonists) && humanc && !character.mind.quiet_round) //Borgs aren't allowed to be antags. Will need to be tweaked if we get true latejoin ais. // yogs - Donor Features
if(SSshuttle.emergency)
switch(SSshuttle.emergency.mode)
if(SHUTTLE_RECALL, SHUTTLE_IDLE)
SSgamemode.make_antag_chance(humanc)
if(SHUTTLE_CALL)
if(SSshuttle.emergency.timeLeft(1) > initial(SSshuttle.emergency_call_time)*0.5)
SSgamemode.make_antag_chance(humanc)
if(humanc && CONFIG_GET(flag/roundstart_traits))
SSquirks.AssignQuirks(humanc, humanc.client, TRUE)
log_manifest(character.mind.key,character.mind,character,latejoin = TRUE)
/mob/dead/new_player/proc/create_character(transfer_after)
spawning = TRUE
close_spawn_windows()
//mind.active = FALSE //we wish to transfer the key manually
var/mob/living/carbon/human/H = new(loc)
var/frn = CONFIG_GET(flag/force_random_names)
if(!frn)
frn = is_banned_from(ckey, "Appearance")
if(QDELETED(src))
return
if(frn)
client.prefs.randomise_appearance_prefs()
client.prefs.apply_prefs_to(H)
H.dna.update_dna_identity()
if(mind)
if(mind.assigned_role)
var/datum/job/J = SSjob.GetJob(mind.assigned_role)
if(H.age < J?.minimal_character_age)
to_chat(client,span_warning("Your character is too young to play your assigned job. Their age has been corrected to the minimum possible."))
H.age = J.minimal_character_age
if(transfer_after)
mind.late_joiner = TRUE
mind.active = FALSE //we wish to transfer the key manually
mind.original_character_slot_index = client.prefs.default_slot
if(!HAS_TRAIT(H, TRAIT_RANDOM_ACCENT))
var/accent_name = client.prefs.read_preference(/datum/preference/choiced/accent)
if (accent_name == ACCENT_NONE)
accent_name = null
mind.accent_name = accent_name
mind.transfer_to(H) //won't transfer key since the mind is not active
mind.set_original_character(H)
H.name = real_name
client.init_verbs()
. = H
new_character = .
if(transfer_after)
transfer_character()
/mob/dead/new_player/proc/transfer_character()
. = new_character
if(!.)
return
new_character.key = key //Manually transfer the key to log them in
new_character.stop_sound_channel(CHANNEL_LOBBYMUSIC)
var/area/joined_area = get_area(new_character.loc)
if(joined_area)
joined_area.on_joining_game(new_character)
SEND_GLOBAL_SIGNAL(COMSIG_GLOB_CREWMEMBER_JOINED, new_character, new_character.mind.assigned_role)
new_character = null
qdel(src)
/mob/dead/new_player/proc/ViewManifest()
if(!client)
return
if(world.time < client.crew_manifest_delay)
return
client.crew_manifest_delay = world.time + (1 SECONDS)
var/dat = "<html><HEAD><meta charset='UTF-8'></HEAD><body>"
dat += "<h4>Crew Manifest</h4>"
dat += GLOB.data_core.get_manifest_html()
dat += "</BODY></HTML>"
src << browse(dat, "window=manifest;size=387x420;can_close=1")
/mob/dead/new_player/Move()
return 0
/mob/dead/new_player/proc/close_spawn_windows()
src << browse(null, "window=playersetup") //closes the player setup window
src << browse(null, "window=preferences") //closes job selection
src << browse(null, "window=mob_occupation")
// Used to make sure that a player has a valid job preference setup, used to knock players out of eligibility for anything if their prefs don't make sense.
// A "valid job preference setup" in this situation means at least having one job set to low, or not having "return to lobby" enabled
// Prevents "antag rolling" by setting antag prefs on, all jobs to never, and "return to lobby if preferences not availible"
// Doing so would previously allow you to roll for antag, then send you back to lobby if you didn't get an antag role
// This also does some admin notification and logging as well, as well as some extra logic to make sure things don't go wrong
/mob/dead/new_player/proc/check_preferences()
if(!client)
return FALSE //Not sure how this would get run without the mob having a client, but let's just be safe.
if(client.prefs.read_preference(/datum/preference/choiced/jobless_role) != RETURNTOLOBBY)
return TRUE
// If they have antags enabled, they're potentially doing this on purpose instead of by accident. Notify admins if so.
var/has_antags = FALSE
if(client.prefs.be_special.len > 0)
has_antags = TRUE
if(client.prefs.job_preferences.len == 0)
if(mind && mind.antag_datums?.len > 0)
message_admins("[src.ckey] has no jobs enabled, but rolled antag. This shouldn't happen, notify coders.")
log_admin("[src.ckey] has rolled antag with no jobs enabled")
return TRUE
if(!ineligible_for_roles)
to_chat(src, span_danger("You have no jobs enabled, along with return to lobby if job is unavailable. This makes you ineligible for any round start role, please update your job preferences."))
ineligible_for_roles = TRUE
ready = PLAYER_NOT_READY
if(has_antags)
log_admin("[src.ckey] just got booted back to lobby with no jobs, but antags enabled.")
message_admins("[src.ckey] just got booted back to lobby with no jobs enabled, but antag rolling enabled. Likely antag rolling abuse.")
return FALSE //This is the only case someone should actually be completely blocked from antag rolling as well
return TRUE
#undef RESET_HUD_INTERVAL