-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (65 loc) · 2.17 KB
/
Program.cs
File metadata and controls
69 lines (65 loc) · 2.17 KB
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
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Security;
using System.Runtime.InteropServices;
namespace PR2_Client
{
static class Program
{
private static string encryptionIV = "JmM5KnkqNXA9MVVOeC9Ucg==";
private static String encryptionKEY = "VUovam5GKndSMHFSSy9kSA==";
public static ServerHandler handler;
static void Main(string[] args)
{
handler = new ServerHandler();
int server_id = handler.promptServer();
Server m_Server = handler.servers[server_id-1];
Console.Write("Enter username: ");
String user = Console.ReadLine();
SecureString pass = getPasswordFromConsole("Enter password: ");
PR2Socket sock = new PR2Socket(m_Server.address, m_Server.port, user, ConvertToUnsecureString(pass), server_id);
while(true)
sock.chat(Console.ReadLine());
// HttpHandler.Send();
// sock.Send("get_customize_info`");
}
public static string ConvertToUnsecureString(this SecureString securePassword)
{
if (securePassword == null)
throw new ArgumentNullException("securePassword");
IntPtr unmanagedString = IntPtr.Zero;
try
{
unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
return Marshal.PtrToStringUni(unmanagedString);
}
finally
{
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
}
}
public static SecureString getPasswordFromConsole(String displayMessage) {
SecureString pass = new SecureString();
Console.Write(displayMessage);
ConsoleKeyInfo key;
do {
key = Console.ReadKey(true);
// Backspace Should Not Work
if (!char.IsControl(key.KeyChar)) {
pass.AppendChar(key.KeyChar);
Console.Write("*");
} else {
if (key.Key == ConsoleKey.Backspace && pass.Length > 0) {
pass.RemoveAt(pass.Length - 1);
Console.Write("\b \b");
}
}
}
// Stops Receving Keys Once Enter is Pressed
while (key.Key != ConsoleKey.Enter);
return pass;
}
}
}