Start implementing server-side functionality.
This commit is contained in:
parent
2b6a265b74
commit
6fadb92a26
8 changed files with 147 additions and 5 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -49,4 +49,6 @@ build
|
|||
*.lock
|
||||
*.hive
|
||||
|
||||
*.g.dart
|
||||
*.g.dart
|
||||
|
||||
out
|
27
Dockerfile
Normal file
27
Dockerfile
Normal file
|
@ -0,0 +1,27 @@
|
|||
FROM debian:latest AS BUILDER
|
||||
# Obtain the Flutter SDK
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
WORKDIR /
|
||||
RUN apt-get update
|
||||
RUN apt-get upgrade -y
|
||||
RUN apt-get install -y git wget curl unzip xz-utils zip libglu1-mesa clang cmake ninja-build pkg-config libgtk3-dev liblzma-dev libstdc++-12-dev
|
||||
|
||||
RUN curl -O flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.22.1-stable.tar.xz
|
||||
RUN tar -xvf flutter.tar.xz
|
||||
|
||||
WORKDIR /flutter
|
||||
RUN export PATH=$PATH:/flutter/bin
|
||||
|
||||
WORKDIR /app
|
||||
RUN /bin/bash /app/compile.sh
|
||||
|
||||
FROM debian:latest
|
||||
WORKDIR /app
|
||||
RUN apt-get update
|
||||
RUN apt-get upgrade -y
|
||||
|
||||
COPY --from=BUILDER /app/out/server /app/server
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
|
@ -1,6 +1,9 @@
|
|||
import 'package:libac_flutter/packets/packets.dart';
|
||||
import 'package:servermanager/packets/ClientPackets.dart';
|
||||
|
||||
void main() async {
|
||||
ClientPackets.register();
|
||||
|
||||
await PacketServer.start();
|
||||
|
||||
print("Server stopping");
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf out/*
|
||||
if [ ! -d out ]
|
||||
then
|
||||
mkdir out
|
||||
fi
|
||||
|
||||
flutter build linux
|
||||
dart build
|
||||
dart compile exe -o out/server bin/server.dart
|
||||
cp -rv build/linux/x64/release/bundle out/client
|
|
@ -52,10 +52,11 @@ class ServerPage extends StatelessWidget {
|
|||
backgroundColor: Constants.TITLEBAR_COLOR,
|
||||
),
|
||||
floatingActionButton: ElevatedButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
// Send login packet to server
|
||||
Settings settings = Settings();
|
||||
settings.client = PacketClient(serverIP.text);
|
||||
settings.client = PacketClient();
|
||||
await settings.client!.startConnect(serverIP.text);
|
||||
},
|
||||
child: Text("Login"),
|
||||
),
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:libac_flutter/nbt/NbtUtils.dart';
|
||||
import 'package:libac_flutter/nbt/Tag.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/nbt/impl/StringTag.dart';
|
||||
import 'package:libac_flutter/packets/packets.dart';
|
||||
import 'package:libac_flutter/utils/uuid/NbtUUID.dart';
|
||||
import 'package:libac_flutter/utils/uuid/UUID.dart';
|
||||
import 'package:servermanager/settings.dart';
|
||||
|
||||
class ClientPackets {
|
||||
static void register() {
|
||||
PacketRegistry reg = PacketRegistry();
|
||||
reg.register(C2SLoginPacket(), () {
|
||||
return C2SLoginPacket();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class C2SLoginPacket implements IPacket {
|
||||
String username = "";
|
||||
String password = "";
|
||||
|
||||
@override
|
||||
void decodeJson(String params) {
|
||||
fromJson(json.decode(params));
|
||||
}
|
||||
|
||||
@override
|
||||
void decodeTag(Tag tag) {
|
||||
CompoundTag ct = tag.asCompoundTag();
|
||||
username = ct.get("username")!.asString();
|
||||
password = ct.get("password")!.asString();
|
||||
}
|
||||
|
||||
@override
|
||||
NetworkDirection direction() {
|
||||
return NetworkDirection.ClientToServer;
|
||||
}
|
||||
|
||||
@override
|
||||
String encodeJson() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
@override
|
||||
Tag encodeTag() {
|
||||
CompoundTag tag = CompoundTag();
|
||||
tag.put("username", StringTag.valueOf(username));
|
||||
tag.put("password", StringTag.valueOf(password));
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@override
|
||||
void fromJson(Map<String, dynamic> js) {
|
||||
username = js['username'] as String;
|
||||
password = js['password'] as String;
|
||||
}
|
||||
|
||||
@override
|
||||
String getChannelID() {
|
||||
return "Login";
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PacketResponse> handleServerPacket() async {
|
||||
S2CResponse response = S2CResponse();
|
||||
|
||||
// Attempt to log in.
|
||||
Settings settings = Settings();
|
||||
if (settings.serverLoginCreds.username == username &&
|
||||
settings.serverLoginCreds.password == password) {
|
||||
NbtUtils.writeBoolean(response.contents, "valid", true);
|
||||
settings.remoteLoginToken = UUID.generate(4);
|
||||
NbtUtils.writeUUID(response.contents, "token",
|
||||
NbtUUID.fromUUID(settings.remoteLoginToken));
|
||||
} else {
|
||||
NbtUtils.writeBoolean(response.contents, "valid", false);
|
||||
}
|
||||
|
||||
return PacketResponse(replyDataTag: response.encodeTag().asCompoundTag());
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {"username": username, "password": password};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> handleClientPacket() async {}
|
||||
}
|
|
@ -4,6 +4,8 @@ import 'package:libac_flutter/nbt/NbtIo.dart';
|
|||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/packets/packets.dart';
|
||||
import 'package:libac_flutter/utils/IOTools.dart';
|
||||
import 'package:libac_flutter/utils/uuid/UUID.dart';
|
||||
import 'package:servermanager/credentials.dart';
|
||||
import 'package:servermanager/mod.dart';
|
||||
import 'package:servermanager/settingsEntry.dart';
|
||||
import 'package:servermanager/statemachine.dart';
|
||||
|
@ -14,6 +16,10 @@ class Settings {
|
|||
|
||||
String steamcmd_path = "";
|
||||
String game_path = "";
|
||||
Credentials serverLoginCreds = Credentials(
|
||||
username: "admin", password: "changeMe123", secret: "", has_2fa: false);
|
||||
UUID remoteLoginToken = UUID.ZERO;
|
||||
|
||||
PacketClient? client;
|
||||
|
||||
StateMachine subsys = StateMachine();
|
||||
|
@ -30,6 +36,8 @@ class Settings {
|
|||
PathHelper.builder(game_path).resolve("settings.dat").build());
|
||||
|
||||
inst = SettingsEntry.deserialize(tag.get("entry") as CompoundTag);
|
||||
serverLoginCreds = Credentials.deserialize(
|
||||
tag.get(Credentials.TAG_NAME)!.asCompoundTag());
|
||||
} catch (E) {
|
||||
inst = SettingsEntry();
|
||||
}
|
||||
|
@ -39,6 +47,7 @@ class Settings {
|
|||
if (!isValid()) return;
|
||||
CompoundTag tag = CompoundTag();
|
||||
tag.put("entry", inst!.serialize());
|
||||
tag.put(Credentials.TAG_NAME, serverLoginCreds.save());
|
||||
|
||||
NbtIo.write(
|
||||
PathHelper.builder(game_path).resolve("settings.dat").build(), tag);
|
||||
|
|
|
@ -42,7 +42,7 @@ dependencies:
|
|||
crypto:
|
||||
libac_flutter:
|
||||
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
|
||||
version: 1.0.8
|
||||
version: 1.0.12
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue