v3 with more features

This commit is contained in:
Soph :3 2024-12-28 03:19:00 +02:00
parent f3c87e1c84
commit 5cb7062d4e
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
6 changed files with 178 additions and 27 deletions

View file

@ -18,6 +18,7 @@ type MessageEvents = {
join: (join: proto.Profile) => void;
leave: (id: string) => void;
chown: () => void;
tokenRecieved: () => void;
serverMessage: (serverMessage: string) => void;
};
@ -33,6 +34,8 @@ interface Player {
export class Client extends (EventEmitter as new () => TypedEmitter<MessageEvents>) {
private ws: WebSocket;
me!: Player;
token?: string;
chatHistory: proto.ServerMessage_Chat[] = [];
room: {
name?: string;
@ -126,10 +129,10 @@ export class Client extends (EventEmitter as new () => TypedEmitter<MessageEvent
}
constructor(url: string, token?: string) {
super();
this.ws = new WebSocket(url.replace("http", "ws"), {
this.ws = new WebSocket(url.replace("http", "ws") + (token ? ("?t=" + token) : ""), {
//@ts-expect-error
headers: {
Origin: url + (token ? ("?t=" + token) : ""),
Origin: url,
"User-Agent": new UserAgent().toString(),
},
protocol: "pianoverse",
@ -166,8 +169,8 @@ export class Client extends (EventEmitter as new () => TypedEmitter<MessageEvent
this.room.owner = decode.chown;
this.emit("chown");
}
if (decode.event == SEventType.MESSAGE) {
this.emit("serverMessage", decode.message);
if (decode.event == SEventType.POPUP) {
this.emit("serverMessage", decode.popup);
}
if (decode.event == SEventType.RATELIMIT) {
console.log("Ratelimit reached! Time left: " + decode.ratelimit);
@ -211,6 +214,10 @@ export class Client extends (EventEmitter as new () => TypedEmitter<MessageEvent
decode.chat!.content
);
}
if (decode.event == SEventType.TOKEN) {
this.token = decode.token;
this.emit("tokenRecieved")
}
});
}
}

View file

@ -1,8 +1,13 @@
import { $ } from "bun";
import * as fs from "fs/promises";
const dumps = ["EAMqERIGc29waGllGgcjZDlhMmMy", "16, 3, 42, 9, 10, 5, 76, 111, 98, 98, 121, 16, 4, 42, 8, 10, 4, 116, 101, 115, 116, 16, 1, 42, 20, 10, 16, 83, 111, 109, 101, 111, 110, 101, 32, 112, 114, 97, 99, 116, 105, 115, 101, 16, 1 "].map(
(z) => {
const realdumps: number[][] | string[] = []
const dumps = realdumps.map(
(z) =>{
if(Array.isArray(z)) {
return new Uint8Array(z);
}
if(z.includes(",")) {
return new Uint8Array(z.split(",").map(z=>+z))
} else {
@ -14,5 +19,6 @@ const dumps = ["EAMqERIGc29waGllGgcjZDlhMmMy", "16, 3, 42, 9, 10, 5, 76, 111, 98
for await (const dump of dumps) {
await fs.writeFile("dump", new Uint8Array(dump.buffer));
const info = await $`~/.local/bin/protobuf_inspector < dump`;
}

View file

@ -2,7 +2,7 @@
"name": "pianoverse",
"module": "index.ts",
"type": "module",
"version": "v2.0.4",
"version": "v3.0.0",
"license": "GPL-3.0-only",
"homepage": "https://git.sad.ovh/sophie/pianoverse",
"bugs": "https://git.sad.ovh/sophie/pianoverse/issues",

4
pb.js

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
// PV version = 9f40d6b9a23fc72f42529f25f4844b283ea7c20b
// PV version = 672593ae79922c7414126e8a84b9bab9d9a4899a
syntax = "proto3";
@ -55,9 +55,18 @@ message ClientMessage {
}
enum Role {
USER = 0;
MODERATOR = 1;
DEVELOPER = 2;
MOD = 1;
DEV = 2;
}
enum NotificationLevel {
INFO = 0;
SUCCESS = 1;
WARNING = 2;
ERROR = 3;
UNRECOGNIZED = -1;
}
message ServerMessage {
enum EventType {
CLEAR = 0;
@ -73,8 +82,10 @@ message ServerMessage {
JOIN = 10;
LEAVE = 11;
RATELIMIT = 12;
MESSAGE = 13;
POPUP = 13;
CHOWN = 14;
NOTIFICATION = 15;
TOKEN = 16;
}
Profile clear = 1;
@ -116,8 +127,18 @@ message ServerMessage {
Profile join = 12;
string leave = 13;
uint32 ratelimit = 14;
string message = 15;
string popup = 15;
string chown = 16;
message Notification {
NotificationLevel level = 1;
string title = 2;
string text = 3;
uint32 timeout = 4;
}
Notification notification = 17;
string token = 18;
}
message Profile {

View file

@ -1,4 +1,4 @@
// PV version = 6202927ae53e43bafd8b8fd3be1ffcaaa45426a3
// PV version = 672593ae79922c7414126e8a84b9bab9d9a4899a
// @generated by protoc-gen-es v1.10.0 with parameter "target=ts"
// @generated from file pianoverse.proto (package pianoverse, syntax proto3)
@ -18,20 +18,58 @@ export enum Role {
USER = 0,
/**
* @generated from enum value: MODERATOR = 1;
* @generated from enum value: MOD = 1;
*/
MODERATOR = 1,
MOD = 1,
/**
* @generated from enum value: DEVELOPER = 2;
* @generated from enum value: DEV = 2;
*/
DEVELOPER = 2,
DEV = 2,
}
// Retrieve enum metadata with: proto3.getEnumType(Role)
proto3.util.setEnumType(Role, "pianoverse.Role", [
{ no: 0, name: "USER" },
{ no: 1, name: "MODERATOR" },
{ no: 2, name: "DEVELOPER" },
{ no: 1, name: "MOD" },
{ no: 2, name: "DEV" },
]);
/**
* @generated from enum pianoverse.NotificationLevel
*/
export enum NotificationLevel {
/**
* @generated from enum value: INFO = 0;
*/
INFO = 0,
/**
* @generated from enum value: SUCCESS = 1;
*/
SUCCESS = 1,
/**
* @generated from enum value: WARNING = 2;
*/
WARNING = 2,
/**
* @generated from enum value: ERROR = 3;
*/
ERROR = 3,
/**
* @generated from enum value: UNRECOGNIZED = -1;
*/
UNRECOGNIZED = -1,
}
// Retrieve enum metadata with: proto3.getEnumType(NotificationLevel)
proto3.util.setEnumType(NotificationLevel, "pianoverse.NotificationLevel", [
{ no: 0, name: "INFO" },
{ no: 1, name: "SUCCESS" },
{ no: 2, name: "WARNING" },
{ no: 3, name: "ERROR" },
{ no: -1, name: "UNRECOGNIZED" },
]);
/**
@ -475,15 +513,25 @@ export class ServerMessage extends Message<ServerMessage> {
ratelimit = 0;
/**
* @generated from field: string message = 15;
* @generated from field: string popup = 15;
*/
message = "";
popup = "";
/**
* @generated from field: string chown = 16;
*/
chown = "";
/**
* @generated from field: pianoverse.ServerMessage.Notification notification = 17;
*/
notification?: ServerMessage_Notification;
/**
* @generated from field: string token = 18;
*/
token = "";
constructor(data?: PartialMessage<ServerMessage>) {
super();
proto3.util.initPartial(data, this);
@ -506,8 +554,10 @@ export class ServerMessage extends Message<ServerMessage> {
{ no: 12, name: "join", kind: "message", T: Profile },
{ no: 13, name: "leave", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 14, name: "ratelimit", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
{ no: 15, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 15, name: "popup", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 16, name: "chown", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 17, name: "notification", kind: "message", T: ServerMessage_Notification },
{ no: 18, name: "token", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ServerMessage {
@ -597,14 +647,24 @@ export enum ServerMessage_EventType {
RATELIMIT = 12,
/**
* @generated from enum value: MESSAGE = 13;
* @generated from enum value: POPUP = 13;
*/
MESSAGE = 13,
POPUP = 13,
/**
* @generated from enum value: CHOWN = 14;
*/
CHOWN = 14,
/**
* @generated from enum value: NOTIFICATION = 15;
*/
NOTIFICATION = 15,
/**
* @generated from enum value: TOKEN = 16;
*/
TOKEN = 16,
}
// Retrieve enum metadata with: proto3.getEnumType(ServerMessage_EventType)
proto3.util.setEnumType(ServerMessage_EventType, "pianoverse.ServerMessage.EventType", [
@ -621,8 +681,10 @@ proto3.util.setEnumType(ServerMessage_EventType, "pianoverse.ServerMessage.Event
{ no: 10, name: "JOIN" },
{ no: 11, name: "LEAVE" },
{ no: 12, name: "RATELIMIT" },
{ no: 13, name: "MESSAGE" },
{ no: 13, name: "POPUP" },
{ no: 14, name: "CHOWN" },
{ no: 15, name: "NOTIFICATION" },
{ no: 16, name: "TOKEN" },
]);
/**
@ -845,6 +907,61 @@ export class ServerMessage_Sustain extends Message<ServerMessage_Sustain> {
}
}
/**
* @generated from message pianoverse.ServerMessage.Notification
*/
export class ServerMessage_Notification extends Message<ServerMessage_Notification> {
/**
* @generated from field: pianoverse.NotificationLevel level = 1;
*/
level = NotificationLevel.INFO;
/**
* @generated from field: string title = 2;
*/
title = "";
/**
* @generated from field: string text = 3;
*/
text = "";
/**
* @generated from field: uint32 timeout = 4;
*/
timeout = 0;
constructor(data?: PartialMessage<ServerMessage_Notification>) {
super();
proto3.util.initPartial(data, this);
}
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "pianoverse.ServerMessage.Notification";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "level", kind: "enum", T: proto3.getEnumType(NotificationLevel) },
{ no: 2, name: "title", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "text", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "timeout", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ServerMessage_Notification {
return new ServerMessage_Notification().fromBinary(bytes, options);
}
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ServerMessage_Notification {
return new ServerMessage_Notification().fromJson(jsonValue, options);
}
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ServerMessage_Notification {
return new ServerMessage_Notification().fromJsonString(jsonString, options);
}
static equals(a: ServerMessage_Notification | PlainMessage<ServerMessage_Notification> | undefined, b: ServerMessage_Notification | PlainMessage<ServerMessage_Notification> | undefined): boolean {
return proto3.util.equals(ServerMessage_Notification, a, b);
}
}
/**
* @generated from message pianoverse.Profile
*/