summaryrefslogtreecommitdiff
path: root/Main.cs
blob: 85306ec5eba175be3f62787175e6e4eda347d41a (plain)
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
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;

    const ConfigFlags raylibConfFlags = 
        //ConfigFlags.FLAG_WINDOW_UNDECORATED |
        //ConfigFlags.FLAG_WINDOW_TRANSPARENT |
        //ConfigFlags.FLAG_WINDOW_MOUSE_PASSTHROUGH |
        //ConfigFlags.FLAG_WINDOW_TOPMOST |
        //ConfigFlags.FLAG_WINDOW_RESIZABLE |
        ConfigFlags.FLAG_VSYNC_HINT;
    
    public static void Main()
    {
        Raylib.SetConfigFlags(raylibConfFlags);
        Raylib.InitWindow(640, 480, "OnekoOnline");
        Raylib.SetTargetFPS(30);

        Oneko LocalOneko = new();

        RenderTexture2D RenderTexture = Raylib.LoadRenderTexture(320,240);

        int port = Config.GetValue("ServerPort", 42069);
        string serverPassword = Config.GetValue("ServerPassword", "");

        if (Config.GetValue("HostServer", false)) {
            Server = new(port, Config.GetValue("ServerMaxUsers", 32));
            Client = new("127.0.0.1", port, serverPassword);
        } else {
            Client = new(Config.GetValue("ServerIP", "pond.sarahduck.ca"), port, serverPassword);
        }

        while (!Raylib.WindowShouldClose())
        {
            //Poll networking
            Client?.Poll();
            Server?.Poll();

            Raylib.BeginTextureMode(RenderTexture);

            Raylib.ClearBackground(Color.GRAY);
            Raylib.DrawText("Oneko Online",12, 12, 8, Color.WHITE);

            Drawable.DrawAll();

            Raylib.EndTextureMode();

            Raylib.BeginDrawing();
            Raylib.DrawTexturePro(RenderTexture.Texture, new Rectangle(0f,0f,320,-240), new Rectangle(0,0,640,480), Vector2.Zero,0f,Color.WHITE);
            Raylib.EndDrawing();
        }

        Client?.Disconnect();
        Server?.Disconnect();

        Drawable.DisposeAll();
        Raylib.CloseWindow();
        Config.SaveFile();
    }
}