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
|
using System.Numerics;
using Raylib_cs;
namespace OnekoOnline;
static class OnekoOnline
{
public static readonly ConfigFile Config = new("config.conf");
public static Net.Server? Server;
public static Net.Client? Client;
public static readonly int WindowX = 320;
public static readonly int WindowY = 240;
public static readonly int WindowScale = Config.GetValue("WindowScale", 2);
public static Vector2 Resolution => new(WindowX, WindowY);
public static readonly bool SpectatorMode = Config.GetValue("SpectatorMode", false);
public static readonly bool HostServer = Config.GetValue("HostServer", false);
public static readonly bool TransparentWindow = Config.GetValue("TransparentWindow", false);
public static Font DefaultFont;
public static string AppTitle {
get => _appTitle;
set {
Raylib.SetWindowTitle(value);
_appTitle = value;
}
}
static string _appTitle = "Oneko Online";
public static void Main()
{
if (TransparentWindow) Raylib.SetConfigFlags(ConfigFlags.TransparentWindow);
Raylib.InitWindow(WindowX*WindowScale, WindowY*WindowScale, AppTitle);
Raylib.SetTargetFPS(30);
Raylib.HideCursor();
MouseLocal LocalMouse = new();
if (!SpectatorMode) {OnekoLocal LocalOneko = new();}
RenderTexture2D RenderTexture = Raylib.LoadRenderTexture(WindowX, WindowY);
int port = Config.GetValue("ServerPort", 42069);
string serverPassword = Config.GetValue("ServerPassword", "");
if (HostServer) {
Server = new(port, Config.GetValue("ServerMaxUsers", 32));
Client = new("127.0.0.1", port, serverPassword);
} else {
string Address = Config.GetValue("ServerIP", "pond.sarahduck.ca");
if (string.IsNullOrEmpty(Address)) {
Console.WriteLine("Server IP empty or invalid, you're offline.");
AppTitle = "Oneko Offline";
}
else Client = new(Address, port, serverPassword);
}
Net.Client.UserConnected += OnekoNet.SpawnNetNeko;
Net.Client.UserConnected += MouseNet.SpawnNetMouse;
DefaultFont = Raylib.LoadFont("misc/MPlusBitmap.fnt");
Color BackgroundColor = Color.Gray;
if (TransparentWindow) BackgroundColor = BackgroundColor with {A = 0};
while (!Raylib.WindowShouldClose())
{
//Poll networking
Client?.Poll();
Server?.Poll();
Raylib.BeginTextureMode(RenderTexture);
Raylib.ClearBackground(BackgroundColor);
Raylib.DrawTextEx(DefaultFont, "こんにちは", new(17,18), 11, 0, Color.White);
Raylib.DrawText(AppTitle, 10, 9, 8, Color.White);
Drawable.DrawAll();
Raylib.EndTextureMode();
Raylib.BeginDrawing();
if (TransparentWindow) Raylib.ClearBackground(Color.Blank);
//Dunno why, but it renders upside down, so I flip it here
Raylib.DrawTexturePro(RenderTexture.Texture, new Rectangle(0f,0f,WindowX,-WindowY), new Rectangle(0,0,WindowX*WindowScale,WindowY*WindowScale), Vector2.Zero,0f,Color.White);
Raylib.EndDrawing();
}
Client?.Disconnect();
Server?.Disconnect();
Drawable.DisposeAll();
Raylib.CloseWindow();
Config.SaveFile();
}
}
|