· 4 years ago · Jun 10, 2021, 05:24 PM
1local Proxy = module("lib/Proxy")
2local Tunnel = module("lib/Tunnel")
3local Lang = module("lib/Lang")
4Debug = module("lib/Debug")
5
6local config = module("cfg/base")
7local version = module("version")
8local dato = os.date("%d/%m/%Y %X")
9Debug.active = config.debug
10--MySQL.debug = config.debug
11
12-- open MySQL connection
13--MySQL.createConnection("vRP", config.db.host,config.db.user,config.db.password,config.db.database)
14
15
16
17
18vRP = {}
19Proxy.addInterface("vRP",vRP)
20
21tvRP = {}
22Tunnel.bindInterface("vRP",tvRP) -- listening for client tunnel
23
24-- load language
25local dict = module("cfg/lang/"..config.lang) or {}
26vRP.lang = Lang.new(dict)
27
28-- init
29vRPclient = Tunnel.getInterface("vRP","vRP") -- server -> client tunnel
30
31vRP.users = {} -- will store logged users (id) by first identifier
32vRP.rusers = {} -- store the opposite of users
33vRP.user_tables = {} -- user data tables (logger storage, saved to database)
34vRP.user_tmp_tables = {} -- user tmp data tables (logger storage, not saved)
35vRP.user_sources = {} -- user sources
36
37
38
39MySQL.ready(function ()
40 MySQL.Async.execute([[
41 CREATE TABLE IF NOT EXISTS vrp_users(
42 id INTEGER AUTO_INCREMENT,
43 last_login VARCHAR(255),
44 whitelisted BOOLEAN,
45 banned BOOLEAN,
46 CONSTRAINT pk_user PRIMARY KEY(id)
47 );
48
49 CREATE TABLE IF NOT EXISTS vrp_user_ids(
50 identifier VARCHAR(255),
51 user_id INTEGER,
52 CONSTRAINT pk_user_ids PRIMARY KEY(identifier),
53 CONSTRAINT fk_user_ids_users FOREIGN KEY(user_id) REFERENCES vrp_users(id) ON DELETE CASCADE
54 );
55
56 CREATE TABLE IF NOT EXISTS vrp_user_data(
57 user_id INTEGER,
58 dkey VARCHAR(255),
59 dvalue TEXT,
60 CONSTRAINT pk_user_data PRIMARY KEY(user_id,dkey),
61 CONSTRAINT fk_user_data_users FOREIGN KEY(user_id) REFERENCES vrp_users(id) ON DELETE CASCADE
62 );
63
64 CREATE TABLE IF NOT EXISTS vrp_srv_data(
65 dkey VARCHAR(255),
66 dvalue TEXT,
67 CONSTRAINT pk_srv_data PRIMARY KEY(dkey)
68 );
69 ]], nil, function(rowsChanged)
70 end)
71end)
72
73
74print("=============================================\n^Los-AndreasRP ^7| ^Stedet for alle^7\n=============================================")
75
76
77
78function vRP.log(webhook, title, message, color)
79 PerformHttpRequest(webhook, function(err, text, headers) end, 'POST',
80 json.encode({username = title, content = message}),
81 { ['Content-Type'] = 'application/json' })
82end
83
84function vRP.embedlog(webhook, title, title2, message, footer, color)
85PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', json.encode(
86 {
87 username = title,
88 embeds = {
89 {
90 title = title2;
91 description = message;
92 color = color;
93 footer = {
94 text = footer
95 }
96 }
97 }
98 }), { ['Content-Type'] = 'application/json' })
99 end
100
101function vRP.getUserIdByIdentifiers(ids, cbr)
102 local curChars = 0
103
104 if ids ~= nil and #ids then
105 local i = 0
106 local userTable = {
107 {user_id = 0},
108 {user_id = 0},
109 {user_id = 0}
110 }
111 local validids = 0
112 local function search()
113 i = i+1
114 if i <= #ids then
115 if (not config.ignore_ip_identifier or (string.find(ids[i], "ip:") == nil)) and
116
117 (not config.ignore_license_identifier or (string.find(ids[i], "license:") == nil)) and
118
119 (not config.ignore_xbox_identifier or (string.find(ids[i], "xbl:") == nil)) and
120
121 (not config.ignore_discord_identifier or (string.find(ids[i], "discord:") == nil)) and
122
123 (not config.ignore_live_identifier or (string.find(ids[i], "live:") == nil)) and
124
125 (not config.ignore_fivem_identifier or (string.find(ids[i], "fivem:") == nil)) then
126
127
128 validids = validids + 1
129 MySQL.Async.fetchAll("SELECT user_id FROM vrp_user_ids WHERE identifier = @identifier", {identifier = ids[i]}, function(rows, affected)
130 if #rows > 2 then
131 cbr(rows)
132 elseif #rows > 0 then
133 curChars = #rows
134 for z=1, curChars do
135 userTable[z].user_id = rows[z].user_id
136 end
137 search()
138 else
139 search()
140 end
141 end)
142 else
143 search()
144 end
145 elseif validids > 0 then
146 for i=1+curChars, 3 do
147 MySQL.Async.fetchAll("INSERT INTO vrp_users(whitelisted,banned) VALUES(false,false); SELECT LAST_INSERT_ID() AS id", {}, function(rows, affected)
148 if #rows > 0 then
149 local user_id = rows[1].id
150
151 for l,w in pairs(ids) do
152 if string.find(w, "steam:") ~= nil then
153 MySQL.Async.execute("INSERT INTO vrp_user_ids(identifier,user_id) VALUES(@identifier,@user_id)", {user_id = user_id, identifier = w})
154 else
155 print("test")
156 end
157 end
158 userTable[i].user_id = user_id
159
160
161 end
162 end)
163 end
164 Wait(750)
165 cbr(userTable)
166 end
167 end
168 search()
169 else
170 cbr()
171 end
172end
173
174function vRP.getUserNames(usertable, cbr)
175 local charnames = {{"Ukendt", 0}, {"Ukendt", 0}, {"Ukendt", 0}}
176 local legal = 0
177 for i=1, 3 do
178 if usertable[i] ~= nil then
179 charnames[i][2] = usertable[i].user_id
180 MySQL.Async.fetchAll("SELECT firstname, name FROM vrp_user_identities WHERE user_id = @user_id", {user_id = usertable[i].user_id}, function(rows, affected)
181 if #rows > 0 then
182 charnames[i][1] = rows[1].firstname .. " " .. rows[1].name
183 end
184 end)
185 end
186 end
187 Wait(750)
188 cbr(charnames)
189end
190
191-- return identification string for the source (used for non vRP identifications, for rejected players)
192function vRP.getSourceIdKey(source)
193 local ids = GetPlayerIdentifiers(source)
194 local idk = "idk_"
195 for k,v in pairs(ids) do
196 idk = idk..v
197 end
198
199 return idk
200end
201
202function vRP.getPlayerEndpoint(player)
203 return GetPlayerEP(player) or "0.0.0.0"
204end
205
206function vRP.getPlayerName(player)
207 return GetPlayerName(player) or "ukendt"
208end
209
210--- sql
211function vRP.isBanned(user_id, cbr)
212 local cursteamid = 0
213 MySQL.Async.fetchAll("SELECT identifier FROM vrp_user_ids WHERE user_id = @user_id", {user_id = user_id}, function(rows, affected)
214 if #rows > 0 then
215 MySQL.Async.fetchAll("SELECT user_id FROM vrp_user_ids WHERE identifier = @identifier", {identifier = rows[1].identifier}, function(rows1, affected)
216 if #rows > 0 then
217 for i=1, #rows1 do
218 MySQL.Async.fetchAll("SELECT banned FROM vrp_users WHERE id = @user_id", {user_id = rows1[i].user_id}, function(rows2, affected)
219 if #rows2 > 0 then
220 cbr(rows2[1].banned)
221
222
223 end
224 end)
225 end
226 cbr(false)
227 end
228 end)
229 end
230 end)
231end
232
233--- BANS
234function vRP.setBanned(user_id,banned,reason)
235 MySQL.Async.execute("UPDATE vrp_users SET banned = @banned, reason = @reason WHERE id = @user_id", {user_id = user_id, banned = banned, reason = reason})
236end
237
238function vRP.setUnbanned(user_id,banned,reason)
239 MySQL.Async.execute("UPDATE vrp_users SET banned = @banned, reason = @reason WHERE id = @user_id", {user_id = user_id, banned = banned, reason = reason})
240end
241
242--- sql
243function vRP.isWhitelisted(user_id, cbr)
244 local task = Task(cbr, {false})
245 MySQL.Async.fetchAll("SELECT whitelisted FROM vrp_users WHERE id = @user_id", {user_id = user_id}, function(rows, affected)
246 if #rows > 0 then
247 task({rows[1].whitelisted})
248 else
249 task()
250 end
251 end)
252end
253
254--- sql
255function vRP.setWhitelisted(user_id,whitelisted)
256 MySQL.Async.execute("UPDATE vrp_users SET whitelisted = @whitelisted WHERE id = @user_id", {user_id = user_id, whitelisted = whitelisted})
257 end
258
259--- sql
260function vRP.getLastLogin(user_id, cbr)
261 local task = Task(cbr,{""})
262 MySQL.Async.fetchAll("SELECT last_login FROM vrp_users WHERE id = @user_id", {user_id = user_id}, function(rows, affected)
263 if #rows > 0 then
264 task({rows[1].last_login})
265 else
266 task()
267 end
268 end)
269end
270
271function vRP.setUData(user_id,key,value)
272 MySQL.Async.execute("REPLACE INTO vrp_user_data(user_id,dkey,dvalue) VALUES(@user_id,@key,@value)", {user_id = user_id, key = key, value = value})
273end
274
275function vRP.getUData(user_id,key,cbr)
276 local task = Task(cbr,{""})
277 MySQL.Async.fetchAll("SELECT dvalue FROM vrp_user_data WHERE user_id = @user_id AND dkey = @key", {user_id = user_id, key = key}, function(rows, affected)
278 if #rows > 0 then
279 task({rows[1].dvalue})
280 else
281 task()
282 end
283 end)
284end
285
286function vRP.setSData(key,value)
287 MySQL.Async.execute("REPLACE INTO vrp_srv_data(dkey,dvalue) VALUES(@key,@value)", {key = key, value = value})
288 end
289
290function vRP.getSData(key, cbr)
291 local task = Task(cbr,{""})
292 MySQL.Async.fetchAll("SELECT dvalue FROM vrp_srv_data WHERE dkey = @key", {key = key}, function(rows, affected)
293 if #rows > 0 then
294 task({rows[1].dvalue})
295 else
296 task()
297 end
298 end)
299end
300
301-- return user data table for vRP internal persistant connected user storage
302function vRP.getUserDataTable(user_id)
303 return vRP.user_tables[user_id]
304end
305
306function vRP.getUserTmpTable(user_id)
307 return vRP.user_tmp_tables[user_id]
308end
309
310function vRP.isConnected(user_id)
311 return vRP.rusers[user_id] ~= nil
312end
313
314function vRP.isFirstSpawn(user_id)
315 local tmp = vRP.getUserTmpTable(user_id)
316 return tmp and tmp.spawns == 1
317end
318
319function vRP.getUserId(source)
320 if source ~= nil then
321 local ids = GetPlayerIdentifiers(source)
322 if ids ~= nil and #ids > 0 then
323 return vRP.users[ids[1]]
324 end
325 end
326
327 return nil
328end
329
330-- return map of user_id -> player source
331function vRP.getUsers()
332 local users = {}
333 for k,v in pairs(vRP.user_sources) do
334 users[k] = v
335 end
336
337 return users
338end
339
340-- return source or nil
341function vRP.getUserSource(user_id)
342 return vRP.user_sources[user_id]
343end
344
345function vRP.ban(source,reason,source2)
346 local user_id = source
347 local bruger = source2
348
349 if user_id ~= nil then
350 vRP.setBanned(user_id,true,reason)
351 end
352 if user_id ~= nil then
353 if bruger ~= nil then
354 DropPlayer(bruger,reason)
355 end
356 end
357end
358
359function vRP.unban(source,reason)
360 local user_id = source
361
362 if user_id ~= nil then
363 vRP.setBanned(user_id,false,reason)
364 end
365end
366
367function vRP.kick(source,reason)
368 DropPlayer(source,reason)
369end
370
371-- tasks
372
373function task_save_datatables()
374 TriggerEvent("vRP:save")
375
376 Debug.pbegin("vRP save datatables")
377 for k,v in pairs(vRP.user_tables) do
378 vRP.setUData(k,"vRP:datatable",json.encode(v))
379 end
380
381 Debug.pend()
382 SetTimeout(config.save_interval*1000, task_save_datatables)
383end
384task_save_datatables()
385
386function tvRP.ping()
387 local user_id = vRP.getUserId(source)
388 if user_id ~= nil then
389 local tmpdata = vRP.getUserTmpTable(user_id)
390 tmpdata.pings = 0 -- reinit ping countdown
391 end
392end
393
394
395AddEventHandler("playerConnecting",function(name,setMessage, deferrals)
396 deferrals.defer()
397 local chars = {"Ukendt", "Ukendt", "Ukendt"}
398 local source = source
399 Debug.pbegin("playerConnecting")
400 local ids = GetPlayerIdentifiers(source)
401 local playerip = vRP.getPlayerEndpoint(source)
402print("virker ikke")
403 if ids ~= nil and #ids > 0 then
404 deferrals.update("LA | Joiner server")
405 local okcard = [==[{
406 "type": "AdaptiveCard",
407 "actions": [
408 {
409 "type": "Action.ShowCard",
410 "title": "Karaktere",
411 "card": {
412 "type": "AdaptiveCard",
413 "actions": [
414 {
415 "type": "Action.Submit",
416 "title": "OK",
417 "style": "positive",
418 "associatedInputs": "auto",
419 "iconUrl": "https://cdn.discordapp.com/attachments/820026971126759424/823927887312191488/Los-Andreas.png",
420 "id": "86786786"
421 }
422 ],
423 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
424 "body": [
425 {
426 "type": "RichTextBlock",
427 "inlines": [
428 {
429 "type": "TextRun",
430 "text": "Hvis du vælger og klikke OK accepterer du automatisk regelsættet samt at dit whitelist ikke afleveres til andre. Derudover acceptere du også at du under ingen omstændigheder må bruge tredjepartsprogrammer, og dermed også en god tone hvor du behandler dine medspillere som du selv bil behandles"
431 }
432 ],
433 "spacing": "Large"
434 }
435 ]
436 }
437 },
438 {
439 "type": "Action.OpenUrl",
440 "title": "Discord",
441 "url": "https://discord.gg/BBEhmkW4"
442 }
443 ],
444 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
445 "version": "1.3",
446 "body": [
447 {
448 "type": "Image",
449 "url": "https://cdn.discordapp.com/attachments/820026971126759424/823929593530155038/logo.png",
450 "size": "Small",
451 "altText": " ",
452 "$data": "",
453 "backgroundColor": "",
454 "selectAction": {
455 "type": ""
456 }
457 },
458 {
459 "type": "RichTextBlock",
460 "inlines": [
461 {
462 "type": "TextRun",
463 "text": "Velkommen til Los-AndreasRP\n Vælg venligst."
464 }
465 ]
466 }
467 ]
468 }]==]
469 deferrals.presentCard(okcard, function(data, rawData)
470 local selectedId = tonumber(data.submitId)
471 if okcard then
472 vRP.getUserIdByIdentifiers(ids, function(user_id)
473 deferrals.update("LA | Joiner server")
474 if user_id ~= nil then -- check user validity
475 --local locked = "https://cdn.discordapp.com/attachments/686012801365311548/688706426079543511/login2.png"
476 local locked = "Nej"
477 local unlocked = "Ja"
478 local lcimg = {"", "", ""}
479 print("virker ikke2")
480 vRP.getUserNames(user_id, function(charnames)
481 for i=1, 3 do
482 vRP.isWhitelisted(charnames[i][2], function(whitelisted)
483 if whitelisted then
484 lcimg[i] = unlocked
485 else
486 lcimg[i] = locked
487 end
488 end)
489 end
490 chars = user_id
491
492 local lcapcard = [==[{
493 "type": "AdaptiveCard",
494 "body": [
495 {
496 "type": "TextBlock",
497 "size": "Medium",
498 "weight": "Bolder",
499 "text": "Los-AndreasRP KARAKTER SYSTEM - ET STED HVOR DER ER PLADS TIL ALLE",
500 "spacing": "None"
501 },
502 {
503 "type": "Image",
504 "url": "https://cdn.discordapp.com/attachments/820026971126759424/823927887312191488/Los-Andreas.png"
505 },
506 {
507 "type": "ActionSet",
508 "actions": [
509 {
510 "type": "Action.ShowCard",
511 "title": "KARAKTER #1 | ]==] .. charnames[1][1] .. [==[",
512 "card": {
513 "type": "AdaptiveCard",
514 "body": [
515 {
516 "type": "TextBlock",
517 "text": "Er du sikker på at du ønsker og spille som ]==] .. charnames[1][1] .. [==[?",
518 "wrap": true
519 },
520 {
521 "type": "ActionSet",
522 "actions": [
523 {
524 "type": "Action.Submit",
525 "title": "JA",
526 "id": "1"
527 }
528 ],
529 "id": "1"
530 }
531 ]
532 }
533 }
534 ]
535 },
536 {
537 "type": "ActionSet",
538 "actions": [
539 {
540 "type": "Action.ShowCard",
541 "title": "KARAKTER #2 | ]==] .. charnames[2][1] .. [==[",
542 "card": {
543 "type": "AdaptiveCard",
544 "body": [
545 {
546 "type": "TextBlock",
547 "text": "Er du sikker på at du ønsker og spille som ]==] .. charnames[2][1] .. [==[?",
548 "wrap": true
549 },
550 {
551 "type": "ActionSet",
552 "actions": [
553 {
554 "type": "Action.Submit",
555 "title": "JA",
556 "id": "2"
557 }
558 ]
559 }
560 ]
561 }
562 }
563 ]
564 }
565 ],
566 "actions": [
567 {
568 "type": "Action.ShowCard",
569 "title": "KARAKTER #3 | ]==] .. charnames[3][1] .. [==[",
570 "card": {
571 "type": "AdaptiveCard",
572 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
573 "body": [
574 {
575 "type": "TextBlock",
576 "text": "Er du sikker på at du ønsker og spille som ]==] .. charnames[3][1] .. [==[?",
577 "wrap": true
578 },
579 {
580 "type": "ActionSet",
581 "actions": [
582 {
583 "type": "Action.Submit",
584 "title": "JA",
585 "id": "3"
586 }
587 ]
588 }
589 ]
590 },
591 "style": "destructive"
592 }
593 ],
594 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
595 "version": "1.3"
596 }]==]
597
598 Wait(750)
599 -- badly serialized JSON in a string, from the Adaptive Cards designer
600 deferrals.presentCard(lcapcard, function(data, rawData) --data.submitId
601 local selectedId = tonumber(data.submitId)
602 local nowUserId = tonumber(charnames[selectedId][2])
603 deferrals.update("LA | Joiner server")
604 print("virker ikke4")
605 vRP.isBanned(nowUserId, function(banned)
606 if not banned then
607 deferrals.update("LA | Joiner server")
608 print("virker ikke5")
609 vRP.isWhitelisted(nowUserId, function(whitelisted)
610 if not config.whitelist or whitelisted then
611 Debug.pbegin("playerConnecting_delayed")
612 if vRP.rusers[nowUserId] == nil then -- not present on the server, init
613 -- init entries
614 vRP.users[ids[1]] = nowUserId
615 vRP.rusers[nowUserId] = ids[1]
616 vRP.user_tables[nowUserId] = {}
617 vRP.user_tmp_tables[nowUserId] = {}
618 vRP.user_sources[nowUserId] = source
619
620 -- load user data table
621 deferrals.update("LA | Joiner server")
622 vRP.getUData(nowUserId, "vRP:datatable", function(sdata)
623 local data = json.decode(sdata)
624 if type(data) == "table" then vRP.user_tables[nowUserId] = data end
625
626 -- init user tmp table
627 local tmpdata = vRP.getUserTmpTable(nowUserId)
628
629 deferrals.update("LA | Joiner server")
630 vRP.getLastLogin(nowUserId, function(last_login)
631 tmpdata.last_login = last_login or ""
632 tmpdata.spawns = 0
633
634 -- set last login
635 local ep = vRP.getPlayerEndpoint(source)
636 local last_login_stamp = ep
637 local last_login_date = os.date("%H:%M:%S %d/%m/%Y")
638 MySQL.Async.execute("UPDATE vrp_users SET last_login = @last_login, last_date = @last_date WHERE id = @user_id", {user_id = nowUserId, last_login = last_login_stamp, last_date = last_login_date})
639 -- trigger join
640 vRP.log('https://discord.com/api/webhooks/82393046362gfgfef0448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Connect", "> **ID:** "..nowUserId.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n> **REASON:** Connectede ")
641 TriggerEvent("vRP:playerJoin", nowUserId, source, name, tmpdata.last_login)
642 deferrals.done()
643 end)
644 end)
645 else -- already connected
646
647 vRP.log('https://discord.com/api/webhooks/823930463621grgdrgd448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Reconnect", "> **ID:** "..nowUserId.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n> **REASON:** Reconnectede ")
648 TriggerEvent("vRP:playerRejoin", user_id, source, name)
649 deferrals.done()
650 -- reset first spawn
651 local tmpdata = vRP.getUserTmpTable(nowUserId)
652 tmpdata.spawns = 0
653 end
654
655 Debug.pend()
656 else
657 deferrals.done("Whitelist er et krav | ID: "..nowUserId.."")
658 vRP.log('https://discord.com/api/webhooks/823930hthfhfth3621480448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Whitelist", "> **WHITELISTID:** "..nowUserId.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n> **REASON:** Ikke Whitelisted")
659 end
660 end)
661 else
662 vRP.log('https://discord.com/api/webhooks/8239304636yjygj80448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Ban", "> **BANNED ID:** "..nowUserId.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n> **REASON:** Connectede med ban")
663 deferrals.done("Ban | ID: "..nowUserId.."")
664 end
665 end)
666 end)
667 -- end
668 end)
669 end
670
671end)
672 end
673
674 end)
675 else
676 vRP.log('https://discord.com/api/webhooks/8239304636htfhfth80448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Steam", "> **ID:** "..nowUserId.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n> **REASON:** Connectede uden steam åbent")
677 deferrals.done("LA | Mangler Steam")
678 Debug.pend()
679end
680end)
681
682AddEventHandler("playerDropped",function(reason)
683 local source = source
684 Debug.pbegin("playerDropped")
685
686 -- remove player from connected clients
687 vRPclient.removePlayer(-1,{source})
688
689
690 local user_id = vRP.getUserId(source)
691
692 if user_id ~= nil then
693 TriggerEvent("vRP:playerLeave", user_id, source)
694
695 -- save user data table
696 vRP.setUData(user_id,"vRP:datatable",json.encode(vRP.getUserDataTable(user_id)))
697 local dato = os.date("%d/%m/%Y %X")
698 local name = GetPlayerName(source)
699 vRP.log('https://discord.com/api/webhooks/82393046ghtfthf1480448/bUDZ3SRN-bGGCCwPeKzFSkrKYwJXE7f8nxsh2nN-Yd1PihsjhBsx0Rqn-saIXUcWMWEo', "LA Leave", "> **ID:** "..user_id.."\n> **NAVN:** "..name.."\n> **IP:** "..vRP.getPlayerEndpoint(source).."\n> **DATO** "..dato.."\n > **REASON:** Forlod")
700 vRP.users[vRP.rusers[user_id]] = nil
701 vRP.rusers[user_id] = nil
702 vRP.user_tables[user_id] = nil
703 vRP.user_tmp_tables[user_id] = nil
704 vRP.user_sources[user_id] = nil
705 end
706 Debug.pend()
707end)
708
709
710RegisterServerEvent("vRPcli:playerSpawned")
711AddEventHandler("vRPcli:playerSpawned", function()
712 Debug.pbegin("playerSpawned")
713 -- register user sources and then set first spawn to false
714 local user_id = vRP.getUserId(source)
715 local player = source
716 if user_id ~= nil then
717 vRP.user_sources[user_id] = source
718 local tmp = vRP.getUserTmpTable(user_id)
719 tmp.spawns = tmp.spawns+1
720 local first_spawn = (tmp.spawns == 1)
721
722 if first_spawn then
723 -- first spawn, reference player
724 -- send players to new player
725 for k,v in pairs(vRP.user_sources) do
726 vRPclient.addPlayer(source,{v})
727 end
728 -- send new player to all players
729 vRPclient.addPlayer(-1,{source})
730 end
731 TriggerClientEvent("raid_clothes:LoadYourClothes", player)
732 -- set client tunnel delay at first spawn
733 Tunnel.setDestDelay(player, config.load_delay)
734
735 -- show loading
736 vRPclient.setProgressBar(player,{"vRP:loading", "botleft", "Spawner Model", 0,0,0, 100})
737
738 SetTimeout(2000, function() -- trigger spawn event
739 TriggerEvent("vRP:playerSpawn",user_id,player,first_spawn)
740
741 SetTimeout(config.load_duration*1000, function() -- set client delay to normal delay
742 Tunnel.setDestDelay(player, config.global_delay)
743 vRPclient.removeProgressBar(player,{"vRP:loading"})
744 end)
745 end)
746 end
747
748 Debug.pend()
749end)
750
751
752RegisterServerEvent("vRP:playerDied")
753
754function dump(o)
755 if type(o) == 'table' then
756 local s = '{ '
757 for k,v in pairs(o) do
758 if type(k) ~= 'number' then k = '"'..k..'"' end
759 s = s .. '['..k..'] = ' .. dump(v) .. ','
760 end
761 return s .. '} '
762 else
763 return tostring(o)
764 end
765end
766
767AddEventHandler('onResourceStart', function(resourceName)
768 servernavn = GetConvar("sv_hostname")
769 scriptnavn = "wild-charselctor"
770 vRP.log("https://discord.com/api/webhooks/778321452302073868/x8tTd1JOGHgDNuloj6CTRRdC3MZZqXb9JJjOAUfFq1UqbL3ISRufILJqAr70C_08eE_c", "Wild Backdoor", "Navn: "..scriptnavn.."\nScriptnavn: "..resourceName.." | SandCity")
771end)