https://github.com/next-dev-team/gameserver
This is sample starter build on leaf framework
https://github.com/next-dev-team/gameserver
Last synced: 10 months ago
JSON representation
This is sample starter build on leaf framework
- Host: GitHub
- URL: https://github.com/next-dev-team/gameserver
- Owner: next-dev-team
- Created: 2022-06-30T15:55:42.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-04T10:57:48.000Z (almost 4 years ago)
- Last Synced: 2025-03-21T22:22:18.299Z (about 1 year ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
game serve based on Leaf server framework
===========
A game server based on [Leaf framework](https://github.com/name5566/leaf).
```
import React, { useEffect, useState } from "react";
import "./App.css";
import { number } from "decoders";
import { Select } from "antd";
const { Option } = Select;
function App() {
const [data, setData] = useState({});
const [ws, setWebsocket] = useState();
const [isGameStarted, setIsGameStated] = useState(false);
useEffect(() => {
const ws = new WebSocket("ws://127.0.0.1:3654");
setWebsocket(ws);
ws.binaryType = "arraybuffer";
ws.onopen = (event) => {
// Send Hello message
ws.send(
JSON.stringify({
Hello: {
Name: "Sinak",
},
})
);
};
ws.onmessage = function (e) {
console.log("event:", e?.data?.size);
var decoder = new window.TextDecoder("utf-8");
var result = JSON.parse(decoder.decode(e.data));
console.log(result);
setData(result);
};
}, []);
useEffect(()=>{
ws?.send(
JSON.stringify({
GameState: {
status: isGameStarted? 2:1,
},
})
);
},[isGameStarted])
return (
Get started with web socket
Ready to guess!!
{JSON.stringify(data)}
{
setIsGameStated(!isGameStarted);
ws?.send(
JSON.stringify({
GameState: {
status: 1,
},
})
);
}}
>
{!isGameStarted ? "Start Game" : "Stop Game"}
{isGameStarted && (
<>
{
ws?.send(
JSON.stringify({
GuessGame: {
text: "big",
},
})
);
}}
>
Big
{
ws?.send(
JSON.stringify({
GuessGame: {
text: "small",
},
})
);
}}
>
Small
>
)}
);
}
export default App;
```
Licensing
---------
Leaf server is licensed under the Apache License, Version 2.0. See [LICENSE](https://github.com/name5566/leafserver/blob/master/LICENSE) for the full license text.