aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Login_manager.cs
diff options
context:
space:
mode:
authorcw2007-01-31 22:09:20 +0000
committercw2007-01-31 22:09:20 +0000
commita82950672860eedeaa23da75421c74e094b5c0a4 (patch)
tree6901851f8e1de03d5eadfbe05e03563126b879a2 /Login_manager.cs
downloadopensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.zip
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.gz
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.bz2
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.xz
Making trunk; applying appropriate license to each file
Diffstat (limited to 'Login_manager.cs')
-rw-r--r--Login_manager.cs163
1 files changed, 163 insertions, 0 deletions
diff --git a/Login_manager.cs b/Login_manager.cs
new file mode 100644
index 0000000..84f475d
--- /dev/null
+++ b/Login_manager.cs
@@ -0,0 +1,163 @@
1/*Copyright (c) 2007 Michael Wright
2
3* Copyright (c) <year>, <copyright holder>
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29using System;
30using System.IO;
31using System.Net;
32using System.Net.Sockets;
33using System.Text;
34using System.Text.RegularExpressions;
35using System.Threading;
36
37namespace Second_server
38{
39 /// <summary>
40 /// Description of Login_manager.
41 /// </summary>
42 public class Login_manager
43 {
44 public Login_manager()
45 {
46
47 }
48
49 public ushort loginPort = 8080;
50 public IPAddress clientAddress = IPAddress.Loopback;
51 public IPAddress remoteAddress = IPAddress.Any;
52 private Socket loginServer;
53 private Random RandomClass = new Random();
54
55 // InitializeLoginProxy: initialize the login proxy
56 private void InitializeLoginProxy() {
57 loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
58 loginServer.Bind(new IPEndPoint(remoteAddress, loginPort));
59 loginServer.Listen(1);
60 }
61
62 public void startup()
63 {
64 this.InitializeLoginProxy();
65 Thread runLoginProxy = new Thread(new ThreadStart(RunLoginProxy));
66 runLoginProxy.IsBackground = true;
67 runLoginProxy.Start();
68 }
69
70 private void RunLoginProxy() {
71 try {
72 for (;;) {
73 Socket client = loginServer.Accept();
74 IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint;
75
76
77 NetworkStream networkStream = new NetworkStream(client);
78 StreamReader networkReader = new StreamReader(networkStream);
79 StreamWriter networkWriter = new StreamWriter(networkStream);
80
81 try
82 {
83 ProxyLogin(networkReader, networkWriter);
84 }
85 catch (Exception e)
86 {
87 Console.WriteLine(e.Message);
88 }
89
90 networkWriter.Close();
91 networkReader.Close();
92 networkStream.Close();
93
94 client.Close();
95
96 // send any packets queued for injection
97
98 }
99 } catch (Exception e) {
100 Console.WriteLine(e.Message);
101 Console.WriteLine(e.StackTrace);
102 }
103 }
104
105 // ProxyLogin: proxy a login request
106 private void ProxyLogin(StreamReader reader, StreamWriter writer) { lock(this) {
107 string line;
108 int contentLength = 0;
109
110 // read HTTP header
111 do {
112 // read one line of the header
113 line = reader.ReadLine();
114
115 // check for premature EOF
116 if (line == null)
117 throw new Exception("EOF in client HTTP header");
118
119 // look for Content-Length
120 Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line);
121 if (match.Success)
122 contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString());
123 } while (line != "");
124 System.Console.WriteLine(line);
125 // read the HTTP body into a buffer
126 char[] content = new char[contentLength];
127 reader.Read(content, 0, contentLength);
128
129
130 // forward the XML-RPC response to the client
131 writer.WriteLine("HTTP/1.0 200 OK");
132 writer.WriteLine("Content-type: text/xml");
133 writer.WriteLine();
134
135
136 StreamReader SR;
137 string lines;
138 SR=File.OpenText("login.dat");
139 lines=SR.ReadLine();
140 writer.WriteLine(lines);
141 lines=SR.ReadLine();
142 int ran=this.RandomClass.Next(1,9999);
143
144 lines="<member><name>session_id</name><value><string>99998888-"+ran.ToString("0000")+"-4f52-8ec1-0b1d5cd6aead</string></value></member>";
145 writer.WriteLine(lines);
146 lines=SR.ReadLine();
147 writer.WriteLine(lines);
148 lines=SR.ReadLine();
149 ran=this.RandomClass.Next(1,9999);
150 lines="<member><name>agent_id</name><value><string>aaaabbbb-8932-"+ran.ToString("0000")+"-8664-58f53e442797</string></value></member>";
151 writer.WriteLine(lines);
152 lines=SR.ReadLine();
153
154 while(lines!="end-mfile")
155 {
156 writer.WriteLine(lines);
157 lines=SR.ReadLine();
158 }
159 SR.Close();
160 }
161 }
162 }
163}