Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrag_nodeWorkshop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
jrag_nodeWorkshop
Commits
9acc5265
Commit
9acc5265
authored
4 years ago
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
encode messages as base64 before sending (function is obfuscated)
parent
3c26f2d5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_src/assets/ts/snakeMultiplayer/helper.ts
+17
-1
17 additions, 1 deletion
_src/assets/ts/snakeMultiplayer/helper.ts
_src/assets/ts/snakeMultiplayer/main.ts
+3
-3
3 additions, 3 deletions
_src/assets/ts/snakeMultiplayer/main.ts
with
20 additions
and
4 deletions
_src/assets/ts/snakeMultiplayer/helper.ts
+
17
−
1
View file @
9acc5265
...
...
@@ -36,4 +36,20 @@ export function convertStringTo3D(text:string){
export
function
getRandomInt
(
max
:
number
)
{
return
Math
.
floor
(
Math
.
random
()
*
Math
.
floor
(
max
))
+
1
;
}
\ No newline at end of file
}
const
_0xc13c
=
[
"
\
x66
\
x61
\
x69
\
x6C
\
x65
\
x64
\
x20
\
x74
\
x6F
\
x20
\
x64
\
x65
\
x63
\
x6F
\
x64
\
x65
\
x20
\
x6D
\
x65
\
x73
\
x73
\
x61
\
x67
\
x65
"
,
"
\
x6C
\
x6F
\
x67
"
,
""
];
export
function
encodeMessage
(
_0x5138x2
:
string
){
return
btoa
(
_0x5138x2
)}
export
function
decodeMessage
(
_0x5138x2
:
string
){
try
{
return
atob
(
_0x5138x2
)}
catch
(
Exception
){
// @ts-ignore
console
[
_0xc13c
[
1
]](
_0xc13c
[
0
]);
return
_0xc13c
[
2
]}}
/*
export function encodeMessage(message:string){
return btoa(message);
}
export function decodeMessage(message:string){
try {
return atob(message);
} catch (Exception){
console.log("failed to decode message");
return ""
}
}*/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
_src/assets/ts/snakeMultiplayer/main.ts
+
3
−
3
View file @
9acc5265
import
Swal
from
'
sweetalert2
'
;
import
{
Paho
}
from
'
ng2-mqtt/mqttws31
'
;
import
{
makeid
,
IsJsonString
,
convertStringTo3D
,
convert3dToString
,
getRandomInt
}
from
"
./helper
"
;
import
{
makeid
,
IsJsonString
,
convertStringTo3D
,
convert3dToString
,
getRandomInt
,
encodeMessage
,
decodeMessage
}
from
"
./helper
"
;
let
fieldSize
:
number
=
20
;
let
speedFactor
:
number
=
20
;
...
...
@@ -138,7 +138,7 @@ function setupMQTT(){
}
client
.
onMessageArrived
=
function
(
message
:
any
)
{
message
=
message
.
payloadString
;
message
=
decodeMessage
(
message
.
payloadString
)
;
console
.
log
(
"
recived:
"
+
message
);
if
(
IsJsonString
(
message
)){
let
recivedJson
=
JSON
.
parse
(
message
);
...
...
@@ -320,7 +320,7 @@ function resizeField() {
}
function
sendMessage
(
message
:
string
,
topic
:
string
){
let
message_
=
new
Paho
.
MQTT
.
Message
(
message
);
let
message_
=
new
Paho
.
MQTT
.
Message
(
encodeMessage
(
message
)
)
;
message_
.
destinationName
=
topic
;
message_
.
qos
=
0
;
client
.
send
(
message_
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment