Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
redm_loadscreen/server.lua at main · Sadicius/redm_loadscreen · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Sadicius
redm_loadscreen
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
redm_loadscreen
/
server.lua
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
155 lines (137 loc) · 7.49 KB
main
Breadcrumbs
redm_loadscreen
/
server.lua
Copy path
Top
File metadata and controls
Code
Blame
155 lines (137 loc) · 7.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
local
latestChangelogEntry
=
nil
--
Stores the single latest entry { content, author, timestamp }
local
backgroundImageUrlList
=
{}
--
Stores a list of image URLs for the background
--
Function to fetch background images
function
FetchBackgroundImages
()
if
not
Config
.
EnableDiscordBackgrounds
then
return
end
local
botToken
=
Config
.
DiscordBotToken
if
not
botToken
or
botToken
==
'
'
or
botToken
==
'
YOUR_DISCORD_BOT_TOKEN_HERE
'
then
return
end
if
not
Config
.
DiscordBackgroundChannelID
or
Config
.
DiscordBackgroundChannelID
==
'
YOUR_BACKGROUND_IMAGE_CHANNEL_ID_HERE
'
then
return
end
local
messageLimit
=
Config
.
DiscordBackgroundMessageLimit
or
50
local
url
=
(
'
https://discord.com/api/v10/channels/%s/messages?limit=%d
'
):
format
(
Config
.
DiscordBackgroundChannelID
,
messageLimit
)
local
headers
=
{
[
'
Authorization
'
]
=
'
Bot
'
..
botToken
,
[
'
Content-Type
'
]
=
'
application/json
'
}
PerformHttpRequest
(
url
,
function
(
errorCode
,
responseData
,
responseHeaders
)
if
errorCode
==
200
then
local
data
=
json
.
decode
(
responseData
)
if
data
and
type
(
data
)
==
'
table
'
then
local
foundImageUrls
=
{}
for
_
,
message
in
ipairs
(
data
)
do
if
message
then
if
message
.
attachments
and
type
(
message
.
attachments
)
==
'
table
'
and
#
message
.
attachments
>
0
then
for
_
,
attachment
in
ipairs
(
message
.
attachments
)
do
if
attachment
then
local
isImage
=
false
--
Default to false
local
contentType
=
attachment
.
content_type
or
'
'
local
attachmentUrl
=
attachment
.
url
--
Store URL locally
--
1. Primary Check: Content Type (Simpler Substring Check)
--
Check if the string starts with "image/"
--
Add a length check first to prevent error if contentType is too short
if
#
contentType
>=
6
and
contentType
:
sub
(
1
,
6
)
==
'
image/
'
then
isImage
=
true
--
2. Fallback Check: URL Extension (only if primary failed AND URL exists)
elseif
attachmentUrl
then
local
urlPath
=
attachmentUrl
:
match
(
"
([^?]+)
"
)
--
Get URL part before any '?'
if
urlPath
then
if
string.match
(
urlPath
:
lower
(),
'
%.(jpe?g|png|gif|webp)$
'
)
then
isImage
=
true
end
end
end
--
Final Decision
if
isImage
and
attachmentUrl
then
table.insert
(
foundImageUrls
,
attachmentUrl
)
end
end
end
end
if
message
.
embeds
and
type
(
message
.
embeds
)
==
'
table
'
then
for
_
,
embed
in
ipairs
(
message
.
embeds
)
do
if
embed
.
image
and
embed
.
image
.
url
then
local
imageUrl
=
embed
.
image
.
url
if
imageUrl
:
match
(
"
([^?]+)
"
)
and
imageUrl
:
lower
():
match
(
"
%.jpe?g$
"
)
or
imageUrl
:
lower
():
match
(
"
%.png$
"
)
or
imageUrl
:
lower
():
match
(
"
%.gif$
"
)
or
imageUrl
:
lower
():
match
(
"
%.webp$
"
)
then
table.insert
(
foundImageUrls
,
imageUrl
)
end
end
end
end
end
end
--
Check if any URLs were actually found
if
#
foundImageUrls
>
0
then
backgroundImageUrlList
=
foundImageUrls
--
Replace the old list
end
end
end
end
,
'
GET
'
,
'
'
,
headers
)
end
function
FetchLatestChangelog
()
if
not
Config
.
EnableChangelog
then
return
end
local
botToken
=
Config
.
DiscordBotToken
--
Direct from Config (Less Secure)
if
not
botToken
or
botToken
==
'
'
or
botToken
==
'
YOUR_DISCORD_BOT_TOKEN_HERE
'
then
return
end
if
not
Config
.
DiscordChannelID
or
Config
.
DiscordChannelID
==
'
YOUR_DISCORD_CHANNEL_ID_HERE
'
then
return
end
local
url
=
(
'
https://discord.com/api/v10/channels/%s/messages?limit=1
'
):
format
(
Config
.
DiscordChannelID
)
local
headers
=
{
[
'
Authorization
'
]
=
'
Bot
'
..
botToken
,
[
'
Content-Type
'
]
=
'
application/json
'
}
PerformHttpRequest
(
url
,
function
(
errorCode
,
responseData
,
responseHeaders
)
if
errorCode
==
200
then
local
data
=
json
.
decode
(
responseData
)
--
Use built-in JSON decode
if
data
and
type
(
data
)
==
'
table
'
and
#
data
>
0
then
local
message
=
data
[
1
]
--
Get the first (and only) message
--
Add safety check for message object itself
if
message
and
message
.
content
and
message
.
content
~=
"
"
then
--
Add safety check for author object
local
authorName
=
"
Unknown
"
if
message
.
author
and
message
.
author
.
username
then
authorName
=
message
.
author
.
username
end
latestChangelogEntry
=
{
content
=
message
.
content
,
author
=
authorName
,
timestamp
=
message
.
timestamp
}
else
latestChangelogEntry
=
nil
--
Clear if latest message is empty/invalid or message object is malformed
end
else
latestChangelogEntry
=
nil
--
Clear cache on parse failure or empty response
end
end
end
,
'
GET
'
,
'
'
,
headers
)
end
SetTimeout
(
3000
,
FetchLatestChangelog
)
SetTimeout
(
4000
,
FetchBackgroundImages
)
AddEventHandler
(
'
playerConnecting
'
,
function
(
playerName
,
setKickReason
,
deferrals
)
local
source
=
source
local
connectingPlayerName
=
GetPlayerName
(
source
)
or
playerName
or
"
Player
"
--
Add fallback
local
serverProjectName
=
GetConvar
(
'
sv_projectName
'
,
'
RedM Server
'
)
--
Get the convar, provide a fallback name
serverProjectName
=
serverProjectName
:
gsub
(
'
%^%d
'
,
'
'
)
local
handoverData
=
{
playerName
=
connectingPlayerName
,
serverName
=
serverProjectName
,
logoUrl
=
Config
.
LogoURL
,
--
logoPosition = Config.LogoPosition, -- Send table posibles positions in loadscreen
enableMusic
=
Config
.
EnableMusic
,
youtubeVideoIds
=
Config
.
YouTubeVideoID
,
initialVolume
=
Config
.
InitialVolume
,
messages
=
Config
.
Messages
,
enableChangelog
=
Config
.
EnableChangelog
,
changelogTitle
=
Config
.
ChangelogTitle
,
changelogEntry
=
latestChangelogEntry
,
--
Send the single cached entry object (can be nil)
enableDiscordBackgrounds
=
Config
.
EnableDiscordBackgrounds
,
backgroundImageUrls
=
backgroundImageUrlList
--
Send the list of URLs
}
--
TriggerClientEvent('basic_loadscreen:client:startLoading', source, true)
deferrals
.
handover
(
handoverData
)
end
)
You can’t perform that action at this time.