Skip to content

Commit d4ecfe9

Browse files
authored
Start server command (#8)
* add `startServer` command * add server start to success, failed and add serverStart command in help * add command `startServer` * add startServer in feature section of README
1 parent f6a5c0b commit d4ecfe9

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

README.ko.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@
2727

2828
| 기능 | 설명 | 이미지 |
2929
|------|-------------|---------|
30+
| 국제화 | 한국어(ko), 영어(en) 를 지원합니다. | |
3031
| 접속중인 유저 대시보드 | 서버에 접속한 유저의 리스트를 보여줍니다. 유저의 변동이 생기면 자동으로 업데이트 됩니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/8a003361-28bc-41fd-9332-6939eea44053) |
3132
| 유저 접속 알림 | 서버에 유저가 접속하거나, 떠나면 로그 채널에 메시지를 보냅니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/80b31996-0770-4276-8d5c-259feb43c70f) |
3233
| 커맨드 | 관리자는 커맨드를 이용하여 서버를 관리할 수 있습니다. `!palbot` 또는 `!palbot help` 라고 쓰면 사용법을 출력합니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/5b5887e4-20f6-4d61-b623-441368305b34) |
3334
| kick(관리자 전용) | 유저를 추방합니다. 다시 접속이 가능합니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/ab25b40c-3bd9-4a98-973b-5f0b0553786f) |
3435
| ban(관리자 전용) | 유저를 차단합니다. 다시 접속이 불가능합니다. | |
35-
| broadcast(관리자 전용) | 서버에 메시지를 전송합니다. 현재 영어만 사용이 가능합니다. [참고](https://github.com/juunini/palworld-rcon/issues/1) | |
36-
| shutdown(관리자 전용) | 서버를 종료합니다. | |
37-
| doExit(관리자 전용) | 서버를 강제 종료합니다. | |
36+
| broadcast(관리자 전용) | 서버에 메시지를 전송합니다. 현재 영어만 사용이 가능합니다. [참고](https://github.com/juunini/palworld-rcon/issues/1) | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/6912d32b-0458-4336-8afc-6b1bb85f417c) |
37+
| shutdown(관리자 전용) | 서버를 종료합니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/29a0caca-803e-4ba0-ad6c-e2b296736b7e) |
38+
| doExit(관리자 전용) | 서버를 강제 종료합니다. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/299174d4-a749-4f14-a7c5-ceb5bc6cdccb) |
3839
| save(관리자 전용) | 서버를 저장합니다. | |
40+
| startServer(관리자 전용) | 서버를 실행합니다. (윈도우: `C:\Program Files (x86)\Steam\steamapps\common\PalServer\PalServer.exe`, 리눅스: `~/Steam/steamapps/common/PalServer/PalServer.sh`) | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/1a7ebb68-eb78-41ac-86a0-1cc89c404ce1) |
3941

4042
## 주의사항
4143

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@
2727

2828
| Feature | Description | Image |
2929
|------|-------------|---------|
30+
| Internationalization | Supports Korean (ko) and English (en). | |
3031
| Connected User Dashboard | Displays a list of users connected to the server. It automatically updates when there are changes in the user list. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/8a003361-28bc-41fd-9332-6939eea44053) |
3132
| User Connection Notification | Sends a message to the log channel when a user connects or disconnects from the server. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/80b31996-0770-4276-8d5c-259feb43c70f) |
3233
| Commands | Administrators can manage the server using commands. Typing `!palbot` or `!palbot help` will display the usage. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/5b5887e4-20f6-4d61-b623-441368305b34) |
3334
| kick (Admin Only) | Kicks a user from the server. They can reconnect afterwards. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/ab25b40c-3bd9-4a98-973b-5f0b0553786f) |
3435
| ban (Admin Only) | Bans a user from the server. They cannot reconnect. | |
35-
| broadcast (Admin Only) | Sends a message to the server. Currently, only English is supported. [Reference](https://github.com/juunini/palworld-rcon/issues/1) | |
36-
| shutdown (Admin Only) | Shuts down the server. | |
37-
| doExit (Admin Only) | Forces the server to exit. | |
36+
| broadcast (Admin Only) | Sends a message to the server. Currently, only English is supported. [Reference](https://github.com/juunini/palworld-rcon/issues/1) | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/6912d32b-0458-4336-8afc-6b1bb85f417c) |
37+
| shutdown (Admin Only) | Shuts down the server. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/29a0caca-803e-4ba0-ad6c-e2b296736b7e) |
38+
| doExit (Admin Only) | Forces the server to exit. | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/299174d4-a749-4f14-a7c5-ceb5bc6cdccb) |
3839
| save (Admin Only) | Saves the server. | |
40+
| startServer (Admin Only) | Starts the server. (Windows: `C:\Program Files (x86)\Steam\steamapps\common\PalServer\PalServer.exe`, Linux: `~/Steam/steamapps/common/PalServer/PalServer.sh`) | ![image](https://github.com/juunini/palworld-discord-bot/assets/41536271/1a7ebb68-eb78-41ac-86a0-1cc89c404ce1) |
3941

4042
## Caution
4143

src/bot/commands/response.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func Response(message string, username string) string {
3333
return doExit()
3434
} else if command == "save" {
3535
return save()
36+
} else if command == "startServer" {
37+
return startServer()
3638
}
3739

3840
return i18n.UnknownCommand

src/bot/commands/startServer.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package commands
2+
3+
import (
4+
"os/exec"
5+
"path/filepath"
6+
"runtime"
7+
8+
"github.com/juunini/palworld-discord-bot/src/console_decoration"
9+
"github.com/juunini/palworld-discord-bot/src/i18n"
10+
)
11+
12+
func startServer() string {
13+
serverPath := "~/Steam/steamapps/common/PalServer/PalServer.sh"
14+
15+
if runtime.GOOS == "windows" {
16+
serverPath = filepath.Join("C:", "/", "Program Files (x86)", "Steam", "steamapps", "common", "PalServer", "PalServer.exe")
17+
}
18+
19+
if err := exec.Command(serverPath, "-useperfthreads", "-NoAsyncLoadingThread", "-UseMultithreadForDS").Start(); err != nil {
20+
console_decoration.PrintError(i18n.FailedToStartServerCommand + ": " + err.Error())
21+
return i18n.FailedToStartServerCommand
22+
}
23+
24+
return i18n.SuccessToStartServerCommand
25+
}

src/i18n/en.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func en() {
1414
FailedToKickCommand = "Failed to Kick command"
1515
FailedToBanCommand = "Failed to Ban command"
1616
FailedToShowPlayerCommand = "Failed to ShowPlayer command"
17+
FailedToStartServerCommand = "Failed to start server"
18+
SuccessToStartServerCommand = "Server started"
1719
WrongParameters = "Wrong parameters"
1820
Help = func(commandPrefix string, isAdmin bool) string {
1921
message := fmt.Sprintf("`%s help` - Show help\n", commandPrefix)
@@ -28,6 +30,7 @@ func en() {
2830
message += fmt.Sprintf("`%s shutdown <seconds> <message>` - Shutdown server after <seconds> with <message>.\n", commandPrefix)
2931
message += fmt.Sprintf("`%s doExit` - Force exit server.\n", commandPrefix)
3032
message += fmt.Sprintf("`%s save` - Save server.", commandPrefix)
33+
message += fmt.Sprintf("`%s startServer` - Start server.", commandPrefix)
3134
return message
3235
}
3336
UnknownCommand = "Unknown command"

src/i18n/i18n.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var FailedToBroadcastCommand string
1919
var FailedToKickCommand string
2020
var FailedToBanCommand string
2121
var FailedToShowPlayerCommand string
22+
var FailedToStartServerCommand string
23+
var SuccessToStartServerCommand string
2224
var WrongParameters string
2325
var Help func(commandPrefix string, isAdmin bool) string
2426
var UnknownCommand string

src/i18n/ko.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func ko() {
1414
FailedToKickCommand = "Kick 커맨드를 실패했습니다."
1515
FailedToBanCommand = "Ban 커맨드를 실패했습니다."
1616
FailedToShowPlayerCommand = "ShowPlayer 커맨드를 실패했습니다."
17+
FailedToStartServerCommand = "서버를 시작하는데 실패했습니다."
18+
SuccessToStartServerCommand = "서버를 실행했습니다."
1719
WrongParameters = "잘못된 파라미터를 입력하셨습니다. 다시 확인해주세요."
1820
Help = func(commandPrefix string, isAdmin bool) string {
1921
message := fmt.Sprintf("`%s help` - 도움말을 표시합니다.\n", commandPrefix)
@@ -28,6 +30,7 @@ func ko() {
2830
message += fmt.Sprintf("`%s shutdown <초> <메시지>` - <메시지>를 전송한 후 <초> 후에 서버를 종료합니다.\n", commandPrefix)
2931
message += fmt.Sprintf("`%s doExit` - 서버를 강제 종료합니다.\n", commandPrefix)
3032
message += fmt.Sprintf("`%s save` - 서버를 저장합니다.", commandPrefix)
33+
message += fmt.Sprintf("`%s startServer` - 서버를 실행합니다.", commandPrefix)
3134
return message
3235
}
3336
UnknownCommand = "알 수 없는 명령어입니다."

0 commit comments

Comments
 (0)