Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to colyseus #28

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9de59ff
game objective implementation
keshav2010 Apr 27, 2023
72c3dd9
bugfixes, phaser 3.55 to 3.60 update
keshav2010 Apr 28, 2023
1a9abc4
Migrate all serverside and common code to typescript, let build .js f…
keshav2010 Nov 17, 2023
9469eb5
SoldierType enum added, and some interfaces for StateMachine class, i…
keshav2010 Nov 17, 2023
5cfebd8
renamed lib folder to core
keshav2010 Nov 17, 2023
82c0a1f
updated README.md
keshav2010 Nov 17, 2023
0e616e8
Added bit more abstraction to sceneObject, applied composition for qu…
keshav2010 Nov 18, 2023
cc0de0d
temporary code
keshav2010 Jan 25, 2024
d897606
[UNSTABLE] | Integration of Colyseus
keshav2010 Feb 11, 2024
38ce48e
soldiers queued text added
keshav2010 Feb 15, 2024
f110e7a
added next spawn message / eta'
keshav2010 Feb 16, 2024
4208376
soldier creation synced b/w client and server'
keshav2010 Feb 16, 2024
e732bd1
sessionId becomes playerId, soldier selection works
keshav2010 Feb 16, 2024
3f91f0f
stability patch and gameplay mech change
keshav2010 Feb 23, 2024
ebf8621
quadtree is updated properly, basic collisions are working fine
keshav2010 Feb 25, 2024
930433c
fixed repulsion and changed mechanics, needs improvement
keshav2010 Feb 25, 2024
4a09a4d
color fix
keshav2010 Feb 25, 2024
dcd40f9
session browser scene added, sessions are displayed, rrefresh added
keshav2010 Feb 29, 2024
813acc8
update
keshav2010 Feb 29, 2024
c071879
update
keshav2010 Mar 1, 2024
948a0b4
chase mechanism fix
keshav2010 Mar 2, 2024
acd1bf7
adde config
keshav2010 Mar 2, 2024
8bdf843
Soldiers are removed from client side when player leaves the game
keshav2010 Mar 3, 2024
f474585
removed player castle when player leaves
keshav2010 Mar 3, 2024
416e132
player name bug fix
keshav2010 Mar 3, 2024
b5c17d8
Player joined notification added
keshav2010 Mar 4, 2024
260ef98
update
keshav2010 Mar 6, 2024
b3ce7be
update
keshav2010 Mar 6, 2024
ef897a3
update
keshav2010 Mar 6, 2024
fa00b82
fi dockerfile and urls
keshav2010 Mar 7, 2024
3e7e08a
docker update
keshav2010 Mar 7, 2024
0ec49b9
package.json
keshav2010 Mar 7, 2024
8c708d3
updte
keshav2010 Mar 7, 2024
253eaf6
docker upate
keshav2010 Mar 7, 2024
a597b6f
force install webpack-cli
keshav2010 Mar 7, 2024
47eda39
updated dockerfile
keshav2010 Mar 7, 2024
55d9d85
use railway's port
keshav2010 Mar 8, 2024
5ed3e59
updated dockerfile
keshav2010 Mar 8, 2024
1cc72bd
update
keshav2010 Mar 8, 2024
a88e1c2
update
keshav2010 Mar 8, 2024
80d43c7
update
keshav2010 Mar 8, 2024
cc392bf
update
keshav2010 Mar 8, 2024
08996c2
install npx
keshav2010 Mar 8, 2024
2a7e907
update
keshav2010 Mar 8, 2024
291d59e
deploy
keshav2010 Mar 8, 2024
ddb1d49
update
keshav2010 Mar 9, 2024
1a83bc5
dockerfile update
keshav2010 Mar 9, 2024
777e591
update
keshav2010 Mar 9, 2024
dc8f5c7
move all to local
keshav2010 Mar 9, 2024
e02b564
add force to webpack
keshav2010 Mar 9, 2024
ace1f68
update package json
keshav2010 Mar 9, 2024
c0dd61f
add process manager tini
keshav2010 Mar 9, 2024
6e4162a
update
keshav2010 Mar 9, 2024
6cbbd91
update
keshav2010 Mar 9, 2024
7645e5f
update
keshav2010 Mar 9, 2024
e7ebe95
update
keshav2010 Mar 9, 2024
41c36b8
update
keshav2010 Mar 9, 2024
7f0389c
update
keshav2010 Mar 10, 2024
b904609
update
keshav2010 Mar 10, 2024
a4338cc
take url from window.location itself
keshav2010 Mar 15, 2024
8440268
fixed issue with attacks, soldier getting removed from scene now
keshav2010 Mar 15, 2024
78e1475
update
keshav2010 Mar 16, 2024
52b0562
fix issue with soldier stuck in chase target state
keshav2010 Mar 16, 2024
938fe68
update
keshav2010 Mar 17, 2024
625ccb3
use wss
keshav2010 Mar 17, 2024
a72363d
protect colyseus monitoring routes
keshav2010 Mar 17, 2024
0c6b1d8
Fixed error
keshav2010 Mar 17, 2024
2ff3aca
Stopped tracking .env File
keshav2010 Mar 19, 2024
68de8e2
Stopped tracking .env File
keshav2010 Mar 19, 2024
8ed8683
Stopped tracking .env File
keshav2010 Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
TICKRATE=24
COUNTDOWN=5
COUNTDOWN=5000
COUNTDOWN_SPAWN_SELECTION=10000
COUNTDOWN_DEFAULT=15000
MAX_SESSION_PER_WORKER=10
MINIMUM_PLAYERS_PER_SESSION=2
MINIMUM_PLAYERS_PER_SESSION=2
COLYSEUS_SERVER_URL=localhost
PORT=3000
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
*.env*
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM node:16
FROM node:18
WORKDIR /rtsApp
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
EXPOSE 3007
CMD ["npm", "start"]
CMD ["npm", "run", "deploy"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ This is a timestep based approach that makes sure server only send delta updates

Both the GIFs shows basic boid avoidance behaviour
[![Image from Gyazo](https://i.gyazo.com/2dec336b740c0d9ecf454c53cac8991f.gif)](https://gyazo.com/2dec336b740c0d9ecf454c53cac8991f)


# Getting Started

1. Build the client side code, this includes phaser related code that is used to draw/render game on the browser.
> npm run build


2. Once done, simply run the server.
> npx ts-node server.ts

3. Check the port where server is running and you're good to go.
1. Create game room
2. open another window on same url, click on join room (it may take few seconds)
42 changes: 0 additions & 42 deletions common/PacketType.js

This file was deleted.

43 changes: 43 additions & 0 deletions common/PacketType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export enum ClientToServerPacketType {
CLIENT_INIT_REQUESTED = "cir",
PLAYER_READY = "plr",
PLAYER_UNREADY = "plur",
SOLDIER_CREATE_REQUESTED = "slcrreq",
SPAWN_POINT_REQUESTED = "spwnpntreq",
SOLDIER_DELETED = "sldel",
SOLDIER_MOVE_REQUESTED = "slmovreq",
PLAYER_JOINED = "pljoin",
SOLDIER_ATTACK_REQUESTED = "sldierattkreq",
CLIENT_SENT_CHAT = "clientchat",
SPAWN_POINT_SELECTED = "spwnpntslct",
SOLDIER_SPAWN_REQUESTED = "unitspwnreq",
}
export enum ServerToClientPacketType {
NEW_CHAT_MESSAGE = "newcm",
SOLDIER_KILLED = "sk",
GAME_STARTED = "gs",
SOLDIER_CREATE_ACK = "sca",
SOLDIER_SPAWN_SCHEDULED = "sspwnsch",
SPAWN_POINT_ACK = "spnpntack",
GAME_STATE_SYNC = "gss",
PLAYER_LEFT = "pl",
PLAYER_INIT = "pi",
PLAYER_LOST = "plyrlost",
SOLDIER_ATTACK_ACK = "saa",
SOLDIER_ATTACKED = "sh",
PLAYER_RESOURCE_UPDATED = "pru",
SOLDIER_POSITION_UPDATED = "spu",
COUNTDOWN_TIME = "cdwn",
SOLDIER_STATE_DEBUG = "debug_soldierState",

SOLDIER_SPAWN_REQUEST_UPDATED = "spawn_request_updated",
}

export const PacketType = {
ByClient: {
...ClientToServerPacketType,
},
ByServer: {
...ServerToClientPacketType,
},
};
46 changes: 0 additions & 46 deletions common/Queue.js

This file was deleted.

44 changes: 44 additions & 0 deletions common/Queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import LinkedList from "dbly-linked-list";
export class Queue<T extends object | number | string = string> {
mList: LinkedList;
constructor() {
this.mList = new LinkedList();
}
enqueue(data: T) {
this.mList.insert(data);
}
dequeue() {
if (this.mList.isEmpty()) return;
this.mList.removeFirst();
}
peekFront() {
const headNode = this.mList.getHeadNode();
if (this.mList.isEmpty() || !headNode) return null;
return headNode.getData<T>();
}
peekEnd() {
const tailNode = this.mList.getTailNode();
if (this.mList.isEmpty() || !tailNode) return null;
return tailNode.getData<T>();
}
toArray() {
return this.mList.toArray().map((d) => d as T);
}
findAt(offset: number) {
if (this.mList.getSize() === 0) return null;
if (offset >= this.mList.getSize() && this.mList.getSize() > 0)
offset = offset % this.mList.getSize();
return this.mList.findAt(offset).getData<T>();
}
removeNode(data: T) {
let contains = this.mList.contains(data);
if (contains) this.mList.removeNode(data);
return contains;
}
isEmpty() {
return this.mList.isEmpty();
}
getSize() {
return this.mList.getSize();
}
}
13 changes: 0 additions & 13 deletions common/SoldierType.js

This file was deleted.

11 changes: 11 additions & 0 deletions common/SoldierType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type SoldierType = "SPEARMAN" | "KNIGHT";
export const SoldierTypeConfig: {
[K in SoldierType]: { cost: number };
} = {
SPEARMAN: {
cost: 10,
},
KNIGHT: {
cost: 20,
},
};
68 changes: 0 additions & 68 deletions common/__tests__/Queue.test.js

This file was deleted.

70 changes: 70 additions & 0 deletions common/__tests__/Queue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Queue } from "../Queue";

describe("Queue", () => {
let queue: Queue<string>;
beforeEach(() => {
queue = new Queue<string>();
});

test("enqueue", () => {
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
expect(queue.getSize()).toBe(3);
expect(queue.peekFront()).toBe("first");
expect(queue.peekEnd()).toBe("third");
});

test("dequeue", () => {
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
queue.dequeue();
expect(queue.getSize()).toBe(2);
expect(queue.peekFront()).toBe("second");
expect(queue.peekEnd()).toBe("third");
});

test("toArray", () => {
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
expect(queue.toArray()).toEqual(
expect.arrayContaining(["first", "second", "third"])
);
});

test("peekFront", () => {
queue.enqueue("first");
expect(queue.peekFront()).toBe("first");
expect(queue.getSize()).toBe(1);
});

test("peekEnd", () => {
queue.enqueue("first");
expect(queue.peekEnd()).toBe("first");
expect(queue.getSize()).toBe(1);
});

test("findAt", () => {
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
expect(queue.findAt(1)).toBe("second");
expect(queue.findAt(3)).toBe("first");
});

test("removeNode", () => {
queue.enqueue("first");
queue.enqueue("second");
queue.enqueue("third");
expect(queue.removeNode("second")).toBe(true);
expect(queue.getSize()).toBe(2);
});

test("isEmpty", () => {
expect(queue.isEmpty()).toBe(true);
queue.enqueue("first");
expect(queue.isEmpty()).toBe(false);
});
});
Loading
Loading