{"id":36737007,"url":"https://github.com/code-game-project/go-server","last_synced_at":"2026-01-12T12:24:07.509Z","repository":{"id":54820533,"uuid":"489971663","full_name":"code-game-project/go-server","owner":"code-game-project","description":"The Go server library for CodeGame.","archived":false,"fork":false,"pushed_at":"2023-05-21T18:47:14.000Z","size":162,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-03-14T23:51:37.052Z","etag":null,"topics":["go","server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-game-project.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-08T14:48:31.000Z","updated_at":"2024-03-14T23:51:37.053Z","dependencies_parsed_at":"2023-01-31T08:46:10.786Z","dependency_job_id":null,"html_url":"https://github.com/code-game-project/go-server","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/code-game-project/go-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-game-project%2Fgo-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-game-project%2Fgo-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-game-project%2Fgo-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-game-project%2Fgo-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-game-project","download_url":"https://codeload.github.com/code-game-project/go-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-game-project%2Fgo-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","server"],"created_at":"2026-01-12T12:24:06.801Z","updated_at":"2026-01-12T12:24:07.504Z","avatar_url":"https://github.com/code-game-project.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go-Server\n![CodeGame Version](https://img.shields.io/badge/CodeGame-v0.8-orange)\n![Go version](https://img.shields.io/github/go-mod/go-version/code-game-project/go-server)\n[![GoDoc](https://pkg.go.dev/badge/github.com/code-game-project/go-server)](https://pkg.go.dev/github.com/code-game-project/go-server)\n\nThe Go server library for [CodeGame](https://code-game.org).\n\n## Installation\n\n```sh\ngo get github.com/code-game-project/go-server/cg\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/Bananenpro/log\"\n\n\t\"github.com/code-game-project/go-server/cg\"\n)\n\ntype Game struct {\n\tcg *cg.Game\n}\n\nfunc (g *Game) OnPlayerJoined(player *cg.Player) {\n\tfmt.Println(\"Player joined:\", player.Username)\n}\n\nfunc (g *Game) OnPlayerLeft(player *cg.Player) {\n\tfmt.Println(\"Player left:\", player.Username)\n}\n\nfunc (g *Game) OnPlayerSocketConnected(player *cg.Player, socket *cg.GameSocket) {\n\tfmt.Println(\"Player connected a new socket:\", player.Username)\n}\n\nfunc (g *Game) OnSpectatorConnected(socket *cg.GameSocket) {\n\tfmt.Println(\"A spectator connected:\", socket.ID)\n}\n\nfunc (g *Game) pollCommands() {\n\tfor {\n\t\tcmd, ok := g.cg.NextCommand() // Alternatively WaitForNextCommand()\n\t\tif !ok {\n\t\t\treturn\n\t\t}\n\t\tg.handleCommand(cmd.Origin, cmd.Cmd)\n\t}\n}\n\nfunc (g *Game) handleCommand(origin *cg.Player, cmd cg.Command) {\n\tfmt.Printf(\"Received '%s' command from '%s'.\\n\", cmd.Name, origin.Username)\n}\n\nfunc (g *Game) Run() {\n\t// Loop until the game is closed.\n\tfor g.cg.Running() {\n\t\tg.pollCommands()\n\n\t\t// game logic\n\n\t\t// 60 FPS\n\t\ttime.Sleep(16 * time.Millisecond)\n\t}\n}\n\nfunc main() {\n\tserver := cg.NewServer(\"my_game\", cg.ServerConfig{\n\t\tPort:                    8080,\n\t\tMaxPlayersPerGame:       20,\n\t\tDeleteInactiveGameDelay: 15 * time.Minute,\n\t\tKickInactivePlayerDelay: 15 * time.Minute,\n\t\tEventsPath:              \"./my_game.cge\",\n\t\tLogoPath:                \"./my_logo.png\",\n\t\tFrontend:                os.DirFS(\"./frontend\"),\n\t\tDisplayName:             \"My Game\",\n\t\tVersion:                 \"1.2.3\",\n\t\tDescription:             \"This is my game.\",\n\t\tRepositoryURL:           \"https://example.com/my-game\",\n\t})\n\n\tserver.Run(func(cgGame *cg.Game, config json.RawMessage) {\n\t\tvar gameConfig struct{} // should be GameConfig from cg-gen-events.\n\t\terr := json.Unmarshal(config, \u0026gameConfig)\n\t\tif err != nil {\n\t\t\tlog.Error(err)\n\t\t\treturn\n\t\t}\n\t\tcgGame.SetConfig(gameConfig)\n\n\t\tgame := Game{\n\t\t\tcg: cgGame,\n\t\t}\n\n\t\t// Register callbacks.\n\t\tcgGame.OnPlayerJoined = game.OnPlayerJoined\n\t\tcgGame.OnPlayerLeft = game.OnPlayerLeft\n\t\tcgGame.OnPlayerSocketConnected = game.OnPlayerSocketConnected\n\t\tcgGame.OnSpectatorConnected = game.OnSpectatorConnected\n\n\t\t// Run the game loop.\n\t\tgame.Run()\n\t})\n}\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2022-2023 Julian Hofmann\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-game-project%2Fgo-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-game-project%2Fgo-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-game-project%2Fgo-server/lists"}