-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
157 lines (143 loc) · 7.1 KB
/
Program.cs
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
using MySQLManager.Database.Session_Details.Interfaces;
using Newtonsoft.Json;
using Ow.Chat;
using Ow.Game;
using Ow.Game.Ticks;
using Ow.Managers;
using Ow.Managers.MySQLManager;
using Ow.Net;
using Ow.Net.netty;
using Ow.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Ow
{
class Program
{
public static TickManager TickManager = new TickManager();
public static void Main(string[] args)
{
try
{
Console.OutputEncoding = Encoding.UTF8;
CheckMySQLConnection();
LoadDatabase();
InitiateServer();
KeepAlive();
}
catch(Exception e)
{
Out.WriteLine("Main void exception: " + e, "Program.cs");
Logger.Log("error_log", $"- [Program.cs] Main void exception: {e}");
}
}
private static void KeepAlive()
{
while (true)
{
var l = Console.ReadLine();
if (l != "" && l.StartsWith("/"))
ExecuteCommand(l);
}
}
public static bool CheckMySQLConnection()
{
if (!SqlDatabaseManager.Initialized)
{
int tries = 0;
TRY:
try
{
SqlDatabaseManager.Initialize();
Console.ForegroundColor = ConsoleColor.Blue;
Out.WriteLine("\x1b[34mWelcome on Wolf_Fr Emulator\x1b[0m");
Out.WriteLine("\x1b[34m", "EMU");
Out.WriteLine("\x1b[34mWW WW OOOOO LL FFFFFFF FFFFFFF RRRRRR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mWW WW OO OO LL FF FF RR RR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mWW W WW OO OO LL FFFF FFFF RRRRRR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34m WW WWW WW OO OO LL FF FF RR RR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34m WW WW OOOO0 LLLLLLL FF _______ FF RR RR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34m \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mEEEEEEE MM MM UU UU LL AAA TTTTTTT OOOOO RRRRRR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mEE MMM MMM UU UU LL AAAAA TTT OO OO RR RR\x1b[0m", "EMU");
Out.WriteLine("\x1b[34mEEEEE MM MM MM UU UU LL AA AA TTT OO OO RRRRRR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mEE MM MM UU UU LL AAAAAAA TTT OO OO RR RR \x1b[0m", "EMU");
Out.WriteLine("\x1b[34mEEEEEEE MM MM UUUUU LLLLLLL AA AA TTT OOOO0 RR RR\x1b[0m", "EMU");
Out.WriteLine("\x1b[34m", "EMU");
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
Out.WriteLine("\x1b[34m▓▓▓▓▓▓▓▓▓▓\x1b[0m \x1b[37m░░░░░░░░\x1b[0m \x1b[31m▓▓▓▓▓▓▓▓▓▓\x1b[0m", "FRA"); // Blue
return true;
}
catch (Exception e)
{
Debug.WriteLine("MYSQL Connection failed: " + e);
Out.WriteLine("MYSQL Connection failed!");
if (tries < 6)
{
Out.WriteLine("Trying to reconnect in .. " + tries + " seconds.");
Thread.Sleep(tries * 1000);
tries++;
goto TRY;
} else Environment.Exit(0);
}
}
return false;
}
public static void LoadDatabase()
{
QueryManager.LoadClans();
QueryManager.LoadShips();
QueryManager.LoadNpcs();
QueryManager.LoadMaps();
}
public static void InitiateServer()
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace };
Handler.AddCommands();
Room.AddRooms();
EventManager.InitiateEvents();
StartListening();
}
public static void StartListening()
{
Task.Factory.StartNew(GameServer.StartListening);
Out.WriteLine("\x1b[32mListening on port " + GameServer.Port + ".\x1b[0m", "GameServer"); // Green
Task.Factory.StartNew(ChatServer.StartListening);
Out.WriteLine("\x1b[33mListening on port " + ChatServer.Port + ".\x1b[0m", "ChatServer"); // Yellow
Task.Factory.StartNew(SocketServer.StartListening);
Out.WriteLine("\x1b[31mListening on port " + SocketServer.Port + ".\x1b[0m", "SocketServer"); // Red
Out.WriteLine("\x1b[34mwolffr.ddns.net\x1b[0m");
Task.Factory.StartNew(TickManager.Tick);
}
public static void ExecuteCommand(string txt)
{
var packet = txt.Replace("/", "");
var splitted = packet.Split(' ');
switch (splitted[0])
{
case "restart":
GameManager.Restart(Convert.ToInt32(splitted[1]));
break;
case "list_players":
foreach (var gameSession in GameManager.GameSessions.Values)
{
if (gameSession != null)
Out.WriteLine($"{gameSession.Player.Name} ({gameSession.Player.Id})");
}
break;
}
}
}
}