Skip to content

Commit

Permalink
feat: Add support for Unreal Tournament 2004
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Jan 16, 2023
1 parent d473ea7 commit 24fe671
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/joinme.click-launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func init() {
gameRouter.AddTitle(titles.Paraworld)
gameRouter.AddTitle(titles.Swat4)
gameRouter.AddTitle(titles.Swat4X)
gameRouter.AddTitle(titles.UT2004)
gameRouter.AddTitle(titles.Vietcong)
}

Expand Down
7 changes: 7 additions & 0 deletions internal/titles/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ var PlusConnectCmdBuilder game_launcher.CommandBuilder = func(fr game_launcher.F
}
return nil, nil
}

var PlainCmdBuilder game_launcher.CommandBuilder = func(fr game_launcher.FileRepository, u *url.URL, config game_launcher.Config, launchType game_launcher.LaunchType) ([]string, error) {
if launchType == game_launcher.LaunchTypeLaunchAndJoin {
return append(config.DefaultArgs, fmt.Sprintf("%s:%s", u.Hostname(), u.Port())), nil
}
return nil, nil
}
51 changes: 51 additions & 0 deletions internal/titles/internal/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,54 @@ func TestPlusConnectCmdBuilder(t *testing.T) {
})
}
}

func TestPlainCmdBuilder(t *testing.T) {
type test struct {
name string
givenHost string
givenDefaultArgs []string
givenLaunchType game_launcher.LaunchType
expectedCmd []string
}

tests := []test{
{
name: "return plain command if launch type is launch and join",
givenHost: net.JoinHostPort("1.1.1.1", "16567"),
givenLaunchType: game_launcher.LaunchTypeLaunchAndJoin,
expectedCmd: []string{net.JoinHostPort("1.1.1.1", "16567")},
},
{
name: "appends to default arguments if any are given",
givenHost: net.JoinHostPort("1.1.1.1", "16567"),
givenDefaultArgs: []string{"+launch"},
givenLaunchType: game_launcher.LaunchTypeLaunchAndJoin,
expectedCmd: []string{"+launch", net.JoinHostPort("1.1.1.1", "16567")},
},
{
name: "return nil slice if launch type is any but launch and join",
givenHost: net.JoinHostPort("1.1.1.1", "16567"),
givenLaunchType: game_launcher.LaunchTypeLaunchOnly,
expectedCmd: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// GIVEN
ctrl := gomock.NewController(t)
mockRepository := NewMockFileRepository(ctrl)
u := &url.URL{Host: tt.givenHost}
config := game_launcher.Config{
DefaultArgs: tt.givenDefaultArgs,
}

// WHEN
cmd, err := PlainCmdBuilder(mockRepository, u, config, tt.givenLaunchType)

// THEN
require.NoError(t, err)
assert.Equal(t, tt.expectedCmd, cmd)
})
}
}
14 changes: 2 additions & 12 deletions internal/titles/swat4.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package titles

import (
"fmt"
"net/url"

"github.com/cetteup/joinme.click-launcher/internal/domain"
"github.com/cetteup/joinme.click-launcher/internal/titles/internal"
"github.com/cetteup/joinme.click-launcher/pkg/game_launcher"
Expand Down Expand Up @@ -34,14 +31,7 @@ var Swat4 = domain.GameTitle{
CloseBeforeLaunch: true,
},
URLValidator: internal.IPPortURLValidator,
CmdBuilder: swat4CmdBuilder,
}

var swat4CmdBuilder game_launcher.CommandBuilder = func(fr game_launcher.FileRepository, u *url.URL, config game_launcher.Config, launchType game_launcher.LaunchType) ([]string, error) {
if launchType == game_launcher.LaunchTypeLaunchAndJoin {
return append(config.DefaultArgs, fmt.Sprintf("%s:%s", u.Hostname(), u.Port())), nil
}
return nil, nil
CmdBuilder: internal.PlainCmdBuilder,
}

var Swat4X = domain.GameTitle{
Expand All @@ -68,5 +58,5 @@ var Swat4X = domain.GameTitle{
CloseBeforeLaunch: true,
},
URLValidator: internal.IPPortURLValidator,
CmdBuilder: swat4CmdBuilder,
CmdBuilder: internal.PlainCmdBuilder,
}
34 changes: 34 additions & 0 deletions internal/titles/ut2004.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package titles

import (
"github.com/cetteup/joinme.click-launcher/internal/domain"
"github.com/cetteup/joinme.click-launcher/internal/titles/internal"
"github.com/cetteup/joinme.click-launcher/pkg/game_launcher"
"github.com/cetteup/joinme.click-launcher/pkg/software_finder"
)

var UT2004 = domain.GameTitle{
Name: "Unreal Tournament 2004",
ProtocolScheme: "ut2004",
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004",
RegistryValueName: "folder",
},
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyCurrentUser, // When installed via Steam, key is CurrentUser instead of LocalMachine
RegistryPath: "SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004",
RegistryValueName: "folder",
},
},
LauncherConfig: game_launcher.Config{
ExecutableName: "UT2004.exe",
ExecutablePath: "System",
CloseBeforeLaunch: true,
},
URLValidator: internal.IPPortURLValidator,
CmdBuilder: internal.PlainCmdBuilder,
}

0 comments on commit 24fe671

Please sign in to comment.