-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
96 lines (81 loc) · 2.44 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.IO;
namespace csharp_server
{
class Program
{
static void Main(string[] args)
{
_connectionHandler c = new _connectionHandler(27015);
while (_writer.readLine() != "/quit") { }
c.shutdown();
}
}
class _writer
{
private static int lastWrite = Console.CursorTop;
private static bool busy = false;
public static string readLine()
{
string output = Console.ReadLine();
lastWrite = Console.CursorTop;
return output;
}
public static void writeLine(string msg, params Object[] args)
{
while (busy) { Thread.Sleep(10); }
busy = true;
int left = Console.CursorLeft,
currentLine = Console.CursorTop,
msgLineSpace;
msg = string.Format(msg, args);
// how many lines does msg need to write
msgLineSpace = (int)Math.Ceiling(msg.Length / (double)Console.WindowWidth);
if (left == 0)
{
Console.WriteLine(msg);
lastWrite = Console.CursorTop;
}
else
{
int linesInBuffer = 1 + currentLine - lastWrite;
Console.MoveBufferArea(0, lastWrite, Console.WindowWidth, linesInBuffer, 0, lastWrite + msgLineSpace);
Console.SetCursorPosition(0, lastWrite);
Console.WriteLine(msg);
lastWrite = Console.CursorTop;
Console.SetCursorPosition(left, currentLine + 1);
}
busy = false;
}
public static void writeLine(char[] msg)
{
writeLine(new string(msg));
}
}
class _config
{
private static uint mMaxMsgSize;
private static uint mMaxNameSize;
public static void setMaxMsgSize(uint pMaxMsgSize) {
mMaxMsgSize = pMaxMsgSize;
}
public static void setMaxNameSize(uint pMaxNameSize)
{
mMaxNameSize = pMaxNameSize;
}
public static uint getMaxMsgSize()
{
return mMaxMsgSize;
}
public static uint getMaxNameSize()
{
return mMaxNameSize;
}
}
}