-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.jsx
More file actions
282 lines (267 loc) · 11 KB
/
server.jsx
File metadata and controls
282 lines (267 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import React, { useState, useEffect } from "react";
import { Server } from "@/entities/Server";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Plus, Server as ServerIcon, Edit, Trash2, Wifi, WifiOff } from "lucide-react";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
export default function Servers() {
const [servers, setServers] = useState([]);
const [showAddDialog, setShowAddDialog] = useState(false);
const [editingServer, setEditingServer] = useState(null);
const [formData, setFormData] = useState({
name: "",
ip: "",
port: 25575,
password: ""
});
useEffect(() => {
loadServers();
}, []);
const loadServers = async () => {
const serverList = await Server.list();
setServers(serverList);
};
const handleSubmit = async (e) => {
e.preventDefault();
if (editingServer) {
await Server.update(editingServer.id, formData);
} else {
await Server.create(formData);
}
setShowAddDialog(false);
setEditingServer(null);
setFormData({ name: "", ip: "", port: 25575, password: "" });
loadServers();
};
const handleEdit = (server) => {
setEditingServer(server);
setFormData({
name: server.name,
ip: server.ip,
port: server.port,
password: server.password
});
setShowAddDialog(true);
};
const handleDelete = async (serverId) => {
if (confirm("Are you sure you want to delete this server?")) {
await Server.delete(serverId);
loadServers();
}
};
const toggleConnection = async (server) => {
// First, deactivate all servers
for (const s of servers) {
if (s.is_active) {
await Server.update(s.id, { is_active: false });
}
}
// Then activate the selected server if it wasn't already active
if (!server.is_active) {
await Server.update(server.id, {
is_active: true,
last_connected: new Date().toISOString()
});
}
loadServers();
};
const closeDialog = () => {
setShowAddDialog(false);
setEditingServer(null);
setFormData({ name: "", ip: "", port: 25575, password: "" });
};
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 text-white">
<div className="container mx-auto p-6 max-w-6xl">
<div className="flex justify-between items-center mb-8">
<div>
<h1 className="text-4xl font-bold mb-2 bg-gradient-to-r from-green-400 to-emerald-500 bg-clip-text text-transparent">
Server Management
</h1>
<p className="text-gray-400">Manage your Minecraft server connections</p>
</div>
<Dialog open={showAddDialog} onOpenChange={setShowAddDialog}>
<DialogTrigger asChild>
<Button className="bg-green-600 hover:bg-green-700">
<Plus className="w-4 h-4 mr-2" />
Add Server
</Button>
</DialogTrigger>
<DialogContent className="bg-gray-800 border-gray-700 text-white">
<DialogHeader>
<DialogTitle>{editingServer ? 'Edit Server' : 'Add New Server'}</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<Label htmlFor="name">Server Name</Label>
<Input
id="name"
value={formData.name}
onChange={(e) => setFormData({...formData, name: e.target.value})}
placeholder="My Minecraft Server"
className="bg-gray-900 border-gray-600 text-white"
required
/>
</div>
<div>
<Label htmlFor="ip">Server IP</Label>
<Input
id="ip"
value={formData.ip}
onChange={(e) => setFormData({...formData, ip: e.target.value})}
placeholder="127.0.0.1 or minecraft.example.com"
className="bg-gray-900 border-gray-600 text-white"
required
/>
</div>
<div>
<Label htmlFor="port">RCON Port</Label>
<Input
id="port"
type="number"
value={formData.port}
onChange={(e) => setFormData({...formData, port: parseInt(e.target.value)})}
placeholder="25575"
className="bg-gray-900 border-gray-600 text-white"
required
/>
</div>
<div>
<Label htmlFor="password">RCON Password</Label>
<Input
id="password"
type="password"
value={formData.password}
onChange={(e) => setFormData({...formData, password: e.target.value})}
placeholder="Your RCON password"
className="bg-gray-900 border-gray-600 text-white"
required
/>
</div>
<div className="flex justify-end gap-3 pt-4">
<Button type="button" variant="outline" onClick={closeDialog} className="border-gray-600">
Cancel
</Button>
<Button type="submit" className="bg-green-600 hover:bg-green-700">
{editingServer ? 'Update Server' : 'Add Server'}
</Button>
</div>
</form>
</DialogContent>
</Dialog>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{servers.map((server) => (
<Card key={server.id} className="bg-gray-800/50 border-gray-700 hover:border-green-400 transition-colors">
<CardHeader className="pb-3">
<div className="flex justify-between items-start">
<CardTitle className="flex items-center gap-2 text-white">
<ServerIcon className="w-5 h-5" />
{server.name}
</CardTitle>
<Badge className={server.is_active ? "bg-green-600" : "bg-gray-600"}>
{server.is_active ? (
<>
<Wifi className="w-3 h-3 mr-1" />
Connected
</>
) : (
<>
<WifiOff className="w-3 h-3 mr-1" />
Disconnected
</>
)}
</Badge>
</div>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2 text-sm">
<div className="flex justify-between">
<span className="text-gray-400">Address:</span>
<span className="text-white font-mono">{server.ip}:{server.port}</span>
</div>
{server.last_connected && (
<div className="flex justify-between">
<span className="text-gray-400">Last connected:</span>
<span className="text-white text-xs">
{new Date(server.last_connected).toLocaleDateString()}
</span>
</div>
)}
</div>
<div className="flex gap-2">
<Button
onClick={() => toggleConnection(server)}
className={server.is_active ? "bg-red-600 hover:bg-red-700" : "bg-green-600 hover:bg-green-700"}
size="sm"
>
{server.is_active ? "Disconnect" : "Connect"}
</Button>
<Button
onClick={() => handleEdit(server)}
variant="outline"
size="sm"
className="border-gray-600 hover:bg-gray-700"
>
<Edit className="w-3 h-3" />
</Button>
<Button
onClick={() => handleDelete(server.id)}
variant="outline"
size="sm"
className="border-red-600 text-red-400 hover:bg-red-600 hover:text-white"
>
<Trash2 className="w-3 h-3" />
</Button>
</div>
</CardContent>
</Card>
))}
{servers.length === 0 && (
<div className="col-span-full text-center py-12">
<ServerIcon className="w-16 h-16 mx-auto mb-4 text-gray-600" />
<h3 className="text-xl font-semibold text-gray-400 mb-2">No servers added</h3>
<p className="text-gray-500 mb-4">Add your first Minecraft server to get started</p>
<Button
onClick={() => setShowAddDialog(true)}
className="bg-green-600 hover:bg-green-700"
>
<Plus className="w-4 h-4 mr-2" />
Add Your First Server
</Button>
</div>
)}
</div>
<Card className="mt-8 bg-blue-900/20 border-blue-700">
<CardHeader>
<CardTitle className="text-blue-400">RCON Setup Guide</CardTitle>
</CardHeader>
<CardContent className="prose prose-invert prose-sm max-w-none">
<div className="space-y-4 text-blue-200">
<div>
<h4 className="text-blue-300 font-semibold">1. Enable RCON on your server</h4>
<p>Add these lines to your server.properties file:</p>
<code className="bg-gray-900 p-2 rounded block text-green-400">
enable-rcon=true<br/>
rcon.port=25575<br/>
rcon.password=yourpassword
</code>
</div>
<div>
<h4 className="text-blue-300 font-semibold">2. Restart your server</h4>
<p>Restart your Minecraft server for changes to take effect.</p>
</div>
<div>
<h4 className="text-blue-300 font-semibold">3. Add server connection</h4>
<p>Use the "Add Server" button above to configure your connection details.</p>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
);
}