Skip to content

Commit

Permalink
[v5.0.1] js typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evolutionleo committed Mar 27, 2023
1 parent 8a36ac6 commit 3d0f7f3
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Client/options/operagx/options_operagx.yy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"option_operagx_display_cursor": true,
"option_operagx_editUrl": "",
"option_operagx_game_name": "${project_name}",
"option_operagx_game_name": "Client",
"option_operagx_guid": "",
"option_operagx_internalShareUrl": "",
"option_operagx_interpolate_pixels": true,
Expand Down
55 changes: 44 additions & 11 deletions JavascriptServer/internal/concepts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,35 @@ import MatchMaker from '#util/matchmaker';
// this is a wrapper around sockets
export default class Client extends SendStuff {
name = '';
socket = null; /** @type {import('ws').WebSocket | import('net').Socket} */
type; /** @type {'ws' | 'tcp'} */
/** @type {import('ws').WebSocket | import('net').Socket} */
socket = null;
/** @type {'ws' | 'tcp'} */
type;
ip;

lobby = null; /** @type {Lobby} */
room = null; /** @type {Room} */
party = null; /** @type {Party} */
/** @type {Lobby} */
lobby = null;
/** @type {Room} */
room = null;
/** @type {Party} */
party = null;

party_invites = [];

account = null; /** @type {Account} */
profile = null; /** @type {Profile} */
/** @type {Account} */
account = null;
/** @type {Profile} */
profile = null;

// used internally in packet.ts
halfpack; /** @type {Buffer} */
/** @type {Buffer} */
halfpack;

entity = null; /** @type {PlayerEntity} */
/** @type {PlayerEntity} */
entity = null;

ping; /** @type {number} */
/** @type {number} */
ping;

room_join_timer = -1; // if >0 - joined recently

Expand Down Expand Up @@ -272,6 +282,10 @@ export default class Client extends SendStuff {
}
}

/**
* @param {Client|IProfile} user_to
* @returns {Promise<IFriendRequest>}
*/
async friendRequestSend(user_to) {
user_to = user_to instanceof Client ? user_to.profile : user_to;
if (!this.logged_in)
Expand All @@ -283,13 +297,21 @@ export default class Client extends SendStuff {
return await FriendRequest.create({ sender, receiver });
}

/**
* @param {Client|IProfile} user_from
* @param {Client|IProfile} user_to
* @returns {Promise<IFriendRequest>}
*/
async friendRequestFind(user_from, user_to) {
user_from = user_from instanceof Client ? user_from.profile : user_from;
user_to = user_to instanceof Client ? user_to.profile : user_to;

return await FriendRequest.findRequestId(user_from._id, user_to._id);
}

/**
* @param {Client|IProfile} user_from
*/
async friendRequestAccept(user_from) {
user_from = user_from instanceof Client ? user_from.profile : user_from;
if (!this.logged_in)
Expand All @@ -302,6 +324,9 @@ export default class Client extends SendStuff {
}
}

/**
* @param {Client|IProfile} user_from
*/
async friendRequestReject(user_from) {
user_from = user_from instanceof Client ? user_from.profile : user_from;
if (!this.logged_in)
Expand All @@ -314,6 +339,9 @@ export default class Client extends SendStuff {
}
}

/**
* @param {Client|IProfile} user_to
*/
async friendRequestCancel(user_to) {
user_to = user_to instanceof Client ? user_to.profile : user_to;
if (!this.logged_in)
Expand All @@ -326,6 +354,9 @@ export default class Client extends SendStuff {
}
}

/**
* @param {Client|IProfile} friend
*/
async friendRemove(friend) {
friend = friend instanceof Client ? friend.profile : friend;
if (!this.logged_in)
Expand All @@ -340,7 +371,6 @@ export default class Client extends SendStuff {
}



partyCreate() {
if (this.party)
this.partyLeave();
Expand All @@ -363,6 +393,9 @@ export default class Client extends SendStuff {
this.sendPartyInviteSent();
}

/**
* @param {string} partyid
*/
partyJoin(partyid) {
let party = partyGet(partyid);
party.addMember(this);
Expand Down
25 changes: 23 additions & 2 deletions JavascriptServer/internal/concepts/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export function lobbyList() {

// in context of an MMO this is a shard/separated world
export default class Lobby extends EventEmitter {
lobbyid = "-1"; // assigned when created
lobbyid = '-1'; // assigned when created
status = 'open';
/** @type {Client[]} */
players = [];
/** @type {Room[]} */
rooms = [];
max_players = global.config.lobby.max_players || undefined; // smells like Java

Expand All @@ -66,6 +68,10 @@ export default class Lobby extends EventEmitter {
}
}

/**
* @param {Client} player
* @returns {void|-1}
*/
addPlayer(player) {
if (this.full) {
trace('warning: can\'t add a player - the lobby is full!');
Expand Down Expand Up @@ -101,6 +107,11 @@ export default class Lobby extends EventEmitter {
}
}

/**
* @param {Client} player
* @param {string?} reason
* @param {boolean?} forced
*/
kickPlayer(player, reason, forced) {
var idx = this.players.indexOf(player);
this.players.splice(idx, 1);
Expand All @@ -115,6 +126,9 @@ export default class Lobby extends EventEmitter {
}
}

/**
* @param {Client} player
*/
addIntoPlay(player) {
if (player.lobby === this) {
player.onPlay();
Expand All @@ -124,10 +138,17 @@ export default class Lobby extends EventEmitter {
}
}

/**
* @param {string} room_name
* @returns {Room} room
*/
findRoomByMapName(room_name) {
return this.rooms.find(r => r.map.name === room_name);
}

/**
* @param {object} data
*/
broadcast(data) {
this.players.forEach(function (player) {
player.write(data);
Expand All @@ -142,7 +163,7 @@ export default class Lobby extends EventEmitter {
}

close() {
// kick all plaayers
// kick all players
this.players.forEach((player) => this.kickPlayer(player, 'lobby is closing!', true));
this.status = 'closed';
}
Expand Down
3 changes: 2 additions & 1 deletion JavascriptServer/internal/schemas/account.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// this section contains a schema for saving players' account info
import trace from '#util/logging';

import { model, Schema } from 'mongoose';
import mongoose from 'mongoose';
const { model, Schema } = mongoose;
import { hashPassword, verifyPassword } from '#util/password_encryption';

// you can edit this schema!
Expand Down
9 changes: 3 additions & 6 deletions JavascriptServer/internal/schemas/friend_request.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { createRequire } from 'module';
const require = createRequire(import.meta.url);

const mongoose = require('mongoose');
const { Schema, model } = mongoose;
import mongoose from 'mongoose';
const { model, Schema } = mongoose;
import Profile from '#schemas/profile';

const friendRequestSchema = new Schema({
Expand Down Expand Up @@ -41,5 +38,5 @@ friendRequestSchema.statics.cancel = async function (req_id) {
await FriendRequest.findByIdAndDelete(req_id);
};

export const FriendRequest = new model('FriendRequest', friendRequestSchema);
export const FriendRequest = model('FriendRequest', friendRequestSchema);
export default FriendRequest;
3 changes: 2 additions & 1 deletion JavascriptServer/internal/schemas/profile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This schema is for profiles
import { Schema, model } from 'mongoose';
import mongoose from 'mongoose';
const { model, Schema } = mongoose;

// this holds the state of the profile
// you can edit this schema!
Expand Down
20 changes: 20 additions & 0 deletions JavascriptServer/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"paths": {
"#schemas/*": ["internal/schemas/*"],
"#entity/*": ["internal/entities/entity_types/*"],
"#entities/*": ["internal/entities/*"],
"#initializers/*": ["internal/initializers/*"],
"#types/*": ["internal/types/*"],
"#concepts/*": ["internal/concepts/*"],
"#util/*": ["internal/util/*"],

"#custom/*": ["custom/*"],
"#internal/*": ["internal/*"],

"#root/*": ["./*"],

"*": ["node_modules/*", "src/*"]
}
}
}
Binary file modified Release/GMClient.zip
Binary file not shown.
Binary file modified Release/JSServer.zip
Binary file not shown.
Binary file modified Release/TSServer.zip
Binary file not shown.
Binary file modified Release/Warp.yymps
Binary file not shown.
20 changes: 20 additions & 0 deletions TypescriptServer/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"paths": {
"#schemas/*": ["internal/schemas/*"],
"#entity/*": ["internal/entities/entity_types/*"],
"#entities/*": ["internal/entities/*"],
"#initializers/*": ["internal/initializers/*"],
"#types/*": ["internal/types/*"],
"#concepts/*": ["internal/concepts/*"],
"#util/*": ["internal/util/*"],

"#custom/*": ["custom/*"],
"#internal/*": ["internal/*"],

"#root/*": ["./*"],

"*": ["node_modules/*", "src/*"]
}
}
}
Loading

0 comments on commit 3d0f7f3

Please sign in to comment.