From e049da31d21e364dbfc36185d6f89afa9ba07b00 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Wed, 19 Apr 2023 13:37:30 -0400 Subject: [PATCH] add 0x0c AuthenticateAndBeamOut to the protocol --- client/play.html | 1 + client/src/index.ts | 16 +++- client/src/protocol/message_c2s.ts | 119 ++++++++++++++++++++++++++++ protocol/src/lib.rs | 11 ++- protocol/src/pbuf/message_c2s.proto | 7 ++ server/src/handler.rs | 3 + 6 files changed, 154 insertions(+), 3 deletions(-) diff --git a/client/play.html b/client/play.html index 350d770e61ad5125026ae9d7f5043434e99c3422..f2886f544801b11b069ae830b6657a5fea0c678a 100644 --- a/client/play.html +++ b/client/play.html @@ -15,6 +15,7 @@

Position: NaN, NaN

Velocity: NaN

Relative to Moon: NaN, NaN

+ diff --git a/client/src/index.ts b/client/src/index.ts index 6582b53ff1c24b52c5b83809511a1d58ed2a5502..2403045b6d4db083efdf14e8864e381dfbed6b4d 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -2,7 +2,12 @@ import {Logger, logSetup} from "./logger"; import {gateway_connect, GatewayClient} from "./gateway"; import {Player} from "./protocol/player"; import {Planet, PlanetType} from "./protocol/planet"; -import {MessageC2SInput, MessageC2SInput_packetInfo} from "./protocol/message_c2s"; +import { + MessageC2SAuthenticateAndBeamOut, + MessageC2SAuthenticateAndBeamOut_packetInfo, + MessageC2SInput, + MessageC2SInput_packetInfo +} from "./protocol/message_c2s"; import {encode} from "./serde"; logSetup(); @@ -53,6 +58,15 @@ async function client_main(server: string, username: string, texture_quality: st if (window.localStorage.getItem("token") !== null && window.localStorage.getItem("user") !== null) { global.can_beam_out = true; + document.getElementById("beamout")!.style.setProperty("display", "block"); + document.getElementById("beamout")!.addEventListener("click", () => { + let msg = MessageC2SAuthenticateAndBeamOut.encode({ + userId: window.localStorage.getItem("user")!, + token: window.localStorage.getItem("token")! + }).finish(); + + global.client?.socket.send(encode(MessageC2SAuthenticateAndBeamOut_packetInfo.type, msg)); + }) } logger.info("Loading textures"); diff --git a/client/src/protocol/message_c2s.ts b/client/src/protocol/message_c2s.ts index 41a99145c139c24bec769bee6f2c2142ba65ab6c..d0780ae9a452190917ab0eedec8c282a288eb98b 100644 --- a/client/src/protocol/message_c2s.ts +++ b/client/src/protocol/message_c2s.ts @@ -199,6 +199,50 @@ export function messageC2SInput_packetInfoToJSON(object: MessageC2SInput_packetI } } +export interface MessageC2SAuthenticateAndBeamOut { + /** The user ID that the client is authenticating as */ + userId: string; + /** The token from the authentication server that the user is authenticating as */ + token: string; +} + +export enum MessageC2SAuthenticateAndBeamOut_packetInfo { + unknown = 0, + type = 12, + UNRECOGNIZED = -1, +} + +export function messageC2SAuthenticateAndBeamOut_packetInfoFromJSON( + object: any, +): MessageC2SAuthenticateAndBeamOut_packetInfo { + switch (object) { + case 0: + case "unknown": + return MessageC2SAuthenticateAndBeamOut_packetInfo.unknown; + case 12: + case "type": + return MessageC2SAuthenticateAndBeamOut_packetInfo.type; + case -1: + case "UNRECOGNIZED": + default: + return MessageC2SAuthenticateAndBeamOut_packetInfo.UNRECOGNIZED; + } +} + +export function messageC2SAuthenticateAndBeamOut_packetInfoToJSON( + object: MessageC2SAuthenticateAndBeamOut_packetInfo, +): string { + switch (object) { + case MessageC2SAuthenticateAndBeamOut_packetInfo.unknown: + return "unknown"; + case MessageC2SAuthenticateAndBeamOut_packetInfo.type: + return "type"; + case MessageC2SAuthenticateAndBeamOut_packetInfo.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + function createBaseMessageC2SHello(): MessageC2SHello { return { version: 0, requestedUsername: "", nextState: 0 }; } @@ -536,6 +580,81 @@ export const MessageC2SInput = { }, }; +function createBaseMessageC2SAuthenticateAndBeamOut(): MessageC2SAuthenticateAndBeamOut { + return { userId: "", token: "" }; +} + +export const MessageC2SAuthenticateAndBeamOut = { + encode(message: MessageC2SAuthenticateAndBeamOut, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.userId !== "") { + writer.uint32(10).string(message.userId); + } + if (message.token !== "") { + writer.uint32(18).string(message.token); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MessageC2SAuthenticateAndBeamOut { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMessageC2SAuthenticateAndBeamOut(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag != 10) { + break; + } + + message.userId = reader.string(); + continue; + case 2: + if (tag != 18) { + break; + } + + message.token = reader.string(); + continue; + } + if ((tag & 7) == 4 || tag == 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): MessageC2SAuthenticateAndBeamOut { + return { + userId: isSet(object.userId) ? String(object.userId) : "", + token: isSet(object.token) ? String(object.token) : "", + }; + }, + + toJSON(message: MessageC2SAuthenticateAndBeamOut): unknown { + const obj: any = {}; + message.userId !== undefined && (obj.userId = message.userId); + message.token !== undefined && (obj.token = message.token); + return obj; + }, + + create, I>>( + base?: I, + ): MessageC2SAuthenticateAndBeamOut { + return MessageC2SAuthenticateAndBeamOut.fromPartial(base ?? {}); + }, + + fromPartial, I>>( + object: I, + ): MessageC2SAuthenticateAndBeamOut { + const message = createBaseMessageC2SAuthenticateAndBeamOut(); + message.userId = object.userId ?? ""; + message.token = object.token ?? ""; + return message; + }, +}; + type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; export type DeepPartial = T extends Builtin ? T diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 0bb618d100c34170fca1305c65421aba8a14a303..01ee527e40c13e18200b2d919dbfa8f57f8f3672 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -1,6 +1,6 @@ use std::error::Error; use protobuf::{Enum, Message}; -use crate::message_c2s::{MessageC2SChat, MessageC2SGoodbye, MessageC2SHello, MessageC2SInput, MessageC2SPing}; +use crate::message_c2s::{MessageC2SAuthenticateAndBeamOut, MessageC2SChat, MessageC2SGoodbye, MessageC2SHello, MessageC2SInput, MessageC2SPing}; use crate::message_s2c::{MessageS2CChat, MessageS2CGoodbye, MessageS2CHello, MessageS2CPlanetData, MessageS2CPlayersUpdate, MessageS2CPong}; use crate::planet::PlanetType; use crate::starkingdoms_protocol::PacketWrapper; @@ -14,7 +14,8 @@ pub enum MessageC2S { Goodbye(MessageC2SGoodbye), Chat(MessageC2SChat), Ping(MessageC2SPing), - Input(MessageC2SInput) + Input(MessageC2SInput), + AuthenticateAndBeamOut(MessageC2SAuthenticateAndBeamOut) } #[derive(Debug)] @@ -48,6 +49,9 @@ impl TryFrom<&[u8]> for MessageC2S { }, _id if _id == message_c2s::message_c2sinput::Packet_info::type_.value() as i64 => { MessageC2S::Input(MessageC2SInput::parse_from_bytes(&pkt.packet_data)?) + }, + _id if _id == message_c2s::message_c2sauthenticate_and_beam_out::Packet_info::type_.value() as i64 => { + MessageC2S::AuthenticateAndBeamOut(MessageC2SAuthenticateAndBeamOut::parse_from_bytes(&pkt.packet_data)?) } _id => { return Err(format!("Unrecognized C2S packet {}", _id).into()); } }; @@ -75,6 +79,9 @@ impl TryInto> for MessageC2S { } MessageC2S::Input(p) => { (message_c2s::message_c2sping::Packet_info::type_.value(), p.write_to_bytes()?) + }, + MessageC2S::AuthenticateAndBeamOut(p) => { + (message_c2s::message_c2sauthenticate_and_beam_out::Packet_info::type_.value(), p.write_to_bytes()?) } }; diff --git a/protocol/src/pbuf/message_c2s.proto b/protocol/src/pbuf/message_c2s.proto index 5a220298c9ff5047e083aa4f5f1e0d626f7e67bf..5e5ea243d242c8e8bba3784192dcca5b0854f624 100644 --- a/protocol/src/pbuf/message_c2s.proto +++ b/protocol/src/pbuf/message_c2s.proto @@ -35,4 +35,11 @@ message MessageC2SInput { bool down_pressed = 2; bool left_pressed = 3; bool right_pressed = 4; +} + +message MessageC2SAuthenticateAndBeamOut { + enum packet_info { unknown = 0; type = 0x0c; } + + string user_id = 1; // The user ID that the client is authenticating as + string token = 2; // The token from the authentication server that the user is authenticating as } \ No newline at end of file diff --git a/server/src/handler.rs b/server/src/handler.rs index d00f376509133090fd384113e69f93e708cdbbb5..c344707bb9a1d9d2a36bba126ab7267726af4626 100644 --- a/server/src/handler.rs +++ b/server/src/handler.rs @@ -208,6 +208,9 @@ pub async fn handle_client(mgr: ClientManager, data: Arc>, r me.input.down = p.down_pressed; me.input.left = p.left_pressed; me.input.right = p.right_pressed; + }, + MessageC2S::AuthenticateAndBeamOut(p) => { + info!("[{}] * Beaming out {} as {} with realm token {}", remote_addr, username, p.user_id, p.token); } } }