diff --git a/project/.gitattributes b/project/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/project/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/project/.gitignore b/project/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/project/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/project/icon.svg b/project/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/project/icon.svg @@ -0,0 +1 @@ + diff --git a/project/icon.svg.import b/project/icon.svg.import new file mode 100644 index 0000000..8cf762a --- /dev/null +++ b/project/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://brayuh2pw38ix" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/project/project.godot b/project/project.godot new file mode 100644 index 0000000..3cb0eff --- /dev/null +++ b/project/project.godot @@ -0,0 +1,15 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="Multiplayer Game Test" +config/features=PackedStringArray("4.2", "Forward Plus") +config/icon="res://icon.svg" diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..1a662c1 --- /dev/null +++ b/server/README.md @@ -0,0 +1 @@ +# multiplayer-game-test diff --git a/server/go.mod b/server/go.mod new file mode 100644 index 0000000..7679732 --- /dev/null +++ b/server/go.mod @@ -0,0 +1,8 @@ +module github.com/vaporvee/multiplayer-game-test + +go 1.21.0 + +require ( + github.com/gorilla/websocket v1.5.1 // indirect + golang.org/x/net v0.17.0 // indirect +) diff --git a/server/go.sum b/server/go.sum new file mode 100644 index 0000000..272772f --- /dev/null +++ b/server/go.sum @@ -0,0 +1,4 @@ +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= diff --git a/server/main.go b/server/main.go new file mode 100644 index 0000000..bff705d --- /dev/null +++ b/server/main.go @@ -0,0 +1,75 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/gorilla/websocket" +) + +var upgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, +} + +// UserToken represents a user token in the database. +type UserToken struct { + UserID string + Token string +} + +// userTokens is a simple in-memory map for demonstration purposes. +var userTokens = make(map[string]UserToken) + +// generateItchOAuthURL generates an OAuth URL for itch.io. +func generateItchOAuthURL(clientID string) string { + return fmt.Sprintf("https://itch.io/user/oauth?client_id=%s&response_type=token", clientID) +} + +// redirectToItchOAuth sends the OAuth URL to the client. +func redirectToItchOAuth(conn *websocket.Conn, clientID string) { + oauthURL := generateItchOAuthURL(clientID) + err := conn.WriteMessage(websocket.TextMessage, []byte(oauthURL)) + if err != nil { + log.Println(err) + } +} + +// saveUserToken saves the user token in the database. +func saveUserToken(userID, token string) { + userTokens[userID] = UserToken{UserID: userID, Token: token} +} + +// handler handles WebSocket connections. +func handler(w http.ResponseWriter, r *http.Request) { + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + log.Println(err) + return + } + defer conn.Close() + + // Example client ID. Replace with your actual client ID. + clientID := "your_client_id_here" + + // Redirect the user to the OAuth URL. + redirectToItchOAuth(conn, clientID) + + // Simulate receiving the token from the client. + // In a real application, you would parse the token from the redirect URL. + userID := "example_user_id" + token := "example_token" + saveUserToken(userID, token) + + // Send a confirmation message to the client. + err = conn.WriteMessage(websocket.TextMessage, []byte("Token saved successfully.")) + if err != nil { + log.Println(err) + } +} + +func main() { + http.HandleFunc("/ws", handler) + log.Fatal(http.ListenAndServe(":8080", nil)) +}