add server message, server chown and chat clearing

This commit is contained in:
Soph :3 2024-07-18 07:49:47 +03:00
parent 3381420a82
commit 0799979fd2
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
3 changed files with 66 additions and 9 deletions

View file

@ -17,6 +17,8 @@ type MessageEvents = {
rooms: (rooms: proto.ServerMessage_Room[]) => void; rooms: (rooms: proto.ServerMessage_Room[]) => void;
join: (join: proto.ServerMessage_Join) => void; join: (join: proto.ServerMessage_Join) => void;
leave: (id: string) => void; leave: (id: string) => void;
chown: () => void;
serverMessage: (serverMessage: string) => void;
}; };
interface Player { interface Player {
@ -140,8 +142,16 @@ export class Client extends (EventEmitter as new () => TypedEmitter<MessageEvent
console.log(data); console.log(data);
return; return;
} }
if(decode.event == SEventType.CHOWN) {
this.room.owner = decode.chown;
this.emit("chown");
}
if(decode.event == SEventType.MESSAGE) {
this.emit("serverMessage", decode.message);
}
if (decode.event == SEventType.RATELIMIT) { if (decode.event == SEventType.RATELIMIT) {
console.log("Ratelimit reached! Type: " + decode.rateLimit); console.log("Ratelimit reached! Time left: " + decode.rateLimit);
} }
if (decode.event == SEventType.JOIN) { if (decode.event == SEventType.JOIN) {
this.players.set(decode.join!.id, decode.join!); this.players.set(decode.join!.id, decode.join!);

View file

@ -1,3 +1,5 @@
// PV version = 13661e19e8c210d990baa4d96aa8905430c709d5
syntax = "proto3"; syntax = "proto3";
package pianoverse; package pianoverse;
@ -17,7 +19,7 @@ message ClientMessage {
SUSTAIN = 10; SUSTAIN = 10;
HEARTBEAT = 11; HEARTBEAT = 11;
BAN = 12; BAN = 12;
OWNER = 13; CHOWN = 13;
} }
EventType event = 1; EventType event = 1;
@ -51,7 +53,7 @@ message ClientMessage {
uint32 hours = 2; uint32 hours = 2;
} }
string owner = 15; string chown = 15;
} }
message ServerMessage { message ServerMessage {
@ -68,6 +70,9 @@ message ServerMessage {
JOIN = 9; JOIN = 9;
LEAVE = 10; LEAVE = 10;
RATELIMIT = 11; RATELIMIT = 11;
MESSAGE = 12;
CHOWN = 13;
CLEAR = 14;
} }
EventType event = 1; EventType event = 1;
@ -122,6 +127,10 @@ message ServerMessage {
string leave = 12; string leave = 12;
int32 rateLimit = 13; int32 rateLimit = 13;
string message = 14;
string chown = 15;
int32 clear = 16;
} }
message Profile { message Profile {

View file

@ -1,3 +1,5 @@
// PV version = 13661e19e8c210d990baa4d96aa8905430c709d5
// @generated by protoc-gen-es v1.10.0 with parameter "target=ts" // @generated by protoc-gen-es v1.10.0 with parameter "target=ts"
// @generated from file pianoverse.proto (package pianoverse, syntax proto3) // @generated from file pianoverse.proto (package pianoverse, syntax proto3)
/* eslint-disable */ /* eslint-disable */
@ -76,9 +78,9 @@ export class ClientMessage extends Message<ClientMessage> {
ban?: ClientMessage_Ban; ban?: ClientMessage_Ban;
/** /**
* @generated from field: string owner = 15; * @generated from field: string chown = 15;
*/ */
owner = ""; chown = "";
constructor(data?: PartialMessage<ClientMessage>) { constructor(data?: PartialMessage<ClientMessage>) {
super(); super();
@ -101,7 +103,7 @@ export class ClientMessage extends Message<ClientMessage> {
{ no: 12, name: "sustain", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, { no: 12, name: "sustain", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 13, name: "heartbeat", kind: "message", T: ClientMessage_Heartbeat }, { no: 13, name: "heartbeat", kind: "message", T: ClientMessage_Heartbeat },
{ no: 14, name: "ban", kind: "message", T: ClientMessage_Ban }, { no: 14, name: "ban", kind: "message", T: ClientMessage_Ban },
{ no: 15, name: "owner", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 15, name: "chown", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]); ]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ClientMessage { static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ClientMessage {
@ -191,9 +193,9 @@ export enum ClientMessage_EventType {
BAN = 12, BAN = 12,
/** /**
* @generated from enum value: OWNER = 13; * @generated from enum value: CHOWN = 13;
*/ */
OWNER = 13, CHOWN = 13,
} }
// Retrieve enum metadata with: proto3.getEnumType(ClientMessage_EventType) // Retrieve enum metadata with: proto3.getEnumType(ClientMessage_EventType)
proto3.util.setEnumType(ClientMessage_EventType, "pianoverse.ClientMessage.EventType", [ proto3.util.setEnumType(ClientMessage_EventType, "pianoverse.ClientMessage.EventType", [
@ -210,7 +212,7 @@ proto3.util.setEnumType(ClientMessage_EventType, "pianoverse.ClientMessage.Event
{ no: 10, name: "SUSTAIN" }, { no: 10, name: "SUSTAIN" },
{ no: 11, name: "HEARTBEAT" }, { no: 11, name: "HEARTBEAT" },
{ no: 12, name: "BAN" }, { no: 12, name: "BAN" },
{ no: 13, name: "OWNER" }, { no: 13, name: "CHOWN" },
]); ]);
/** /**
@ -399,6 +401,21 @@ export class ServerMessage extends Message<ServerMessage> {
*/ */
rateLimit = 0; rateLimit = 0;
/**
* @generated from field: string message = 14;
*/
message = "";
/**
* @generated from field: string chown = 15;
*/
chown = "";
/**
* @generated from field: int32 clear = 16;
*/
clear = 0;
constructor(data?: PartialMessage<ServerMessage>) { constructor(data?: PartialMessage<ServerMessage>) {
super(); super();
proto3.util.initPartial(data, this); proto3.util.initPartial(data, this);
@ -420,6 +437,9 @@ export class ServerMessage extends Message<ServerMessage> {
{ no: 11, name: "join", kind: "message", T: ServerMessage_Join }, { no: 11, name: "join", kind: "message", T: ServerMessage_Join },
{ no: 12, name: "leave", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 12, name: "leave", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 13, name: "rateLimit", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, { no: 13, name: "rateLimit", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
{ no: 14, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 15, name: "chown", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 16, name: "clear", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
]); ]);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ServerMessage { static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ServerMessage {
@ -502,6 +522,21 @@ export enum ServerMessage_EventType {
* @generated from enum value: RATELIMIT = 11; * @generated from enum value: RATELIMIT = 11;
*/ */
RATELIMIT = 11, RATELIMIT = 11,
/**
* @generated from enum value: MESSAGE = 12;
*/
MESSAGE = 12,
/**
* @generated from enum value: CHOWN = 13;
*/
CHOWN = 13,
/**
* @generated from enum value: CLEAR = 14;
*/
CLEAR = 14,
} }
// Retrieve enum metadata with: proto3.getEnumType(ServerMessage_EventType) // Retrieve enum metadata with: proto3.getEnumType(ServerMessage_EventType)
proto3.util.setEnumType(ServerMessage_EventType, "pianoverse.ServerMessage.EventType", [ proto3.util.setEnumType(ServerMessage_EventType, "pianoverse.ServerMessage.EventType", [
@ -517,6 +552,9 @@ proto3.util.setEnumType(ServerMessage_EventType, "pianoverse.ServerMessage.Event
{ no: 9, name: "JOIN" }, { no: 9, name: "JOIN" },
{ no: 10, name: "LEAVE" }, { no: 10, name: "LEAVE" },
{ no: 11, name: "RATELIMIT" }, { no: 11, name: "RATELIMIT" },
{ no: 12, name: "MESSAGE" },
{ no: 13, name: "CHOWN" },
{ no: 14, name: "CLEAR" },
]); ]);
/** /**