Skip to content

Commit

Permalink
chore(deps): add rusty-motors-chat as a dependency (#2123)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new chat module, enhancing communication capabilities
within the application.
- Added support for handling messages through a new callback type for
game socket connections.
- Implemented a function to receive and process incoming chat messages
(currently in preliminary state).
- **Configuration**
- Established foundational configuration for the chat module, including
TypeScript and testing setups.
- Expanded workspace scope to include additional modules in the source
directory.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
drazisil committed Sep 15, 2024
2 parents ebb02fe + 9888210 commit 1a1fe3d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"lobby": "link:packages/lobby",
"moment": "^2.29.4",
"pino": "^9.3.2",
"rusty-motors-chat": "link:src/chat",
"rusty-motors-cli": "link:packages/cli",
"rusty-motors-connection": "link:packages/connection",
"rusty-motors-database": "link:packages/database",
Expand Down
17 changes: 12 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- 'packages/*'
- "src/*"
46 changes: 46 additions & 0 deletions src/chat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
GameMessage,
getServerLogger,
type ServiceResponse,
} from "rusty-motors-shared";
import type { Serializable } from "rusty-motors-shared-packets";

/**
* Receive chat data
*
* @param connectionId - Connection ID
* @param message - Message
* @returns Service response
*/
async function receiveChatData({
connectionId,
message,
}: {
connectionId: string;
message: Serializable;
}): Promise<ServiceResponse> {
const log = getServerLogger({});

log.info(`Received chat data from connection ${connectionId}`);
log.debug(`Message: ${message.toHexString()}`);

const inboundMessage = new GameMessage(0);
inboundMessage.deserialize(message.serialize());

log.debug(`Deserialized message: ${inboundMessage.toHexString()}`);

const id = inboundMessage._header.id;

log.debug(`Message ID: ${id}`);

throw new Error(
`Unable to process chat data from connection ${connectionId}, data: ${message.toHexString()}`,
);

return {
connectionId,
messages: [],
};
}

export { receiveChatData };
17 changes: 17 additions & 0 deletions src/chat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "rusty-motors-chat",
"version": "1.0.0",
"exports": {
".": {
"import": "./index.js"
}
},
"scripts": {
"test": "echo \"Error: no tests yet\" && exit 0"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
11 changes: 11 additions & 0 deletions src/chat/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": true,
"composite": true
},
"include": [
"index.ts",
"**/*.ts"
]
}
1 change: 1 addition & 0 deletions src/chat/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type GameSocketCallback = (messages: Buffer[]) => void;
22 changes: 22 additions & 0 deletions src/chat/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
all: true,
exclude: [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"bin/**/*.ts",
"ecosystem.config.js",
"migrate.ts",
"packages/**/*.d.ts",
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
},
});

0 comments on commit 1a1fe3d

Please sign in to comment.