aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ogs/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'ogs/common/src')
-rw-r--r--ogs/common/src/OGS-Console.cs181
-rw-r--r--ogs/common/src/Util.cs87
-rw-r--r--ogs/common/src/VersionInfo.cs.template37
3 files changed, 305 insertions, 0 deletions
diff --git a/ogs/common/src/OGS-Console.cs b/ogs/common/src/OGS-Console.cs
new file mode 100644
index 0000000..c35c75c
--- /dev/null
+++ b/ogs/common/src/OGS-Console.cs
@@ -0,0 +1,181 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Threading;
32using System.IO;
33using System.Net;
34using ServerConsole;
35
36namespace OpenGridServices
37{
38 /// <summary>
39 /// Description of ServerConsole.
40 /// </summary>
41 public class MServerConsole : ConsoleBase
42 {
43
44 private ConsoleType ConsType;
45 StreamWriter Log;
46 public conscmd_callback cmdparser;
47 public string componentname;
48
49 // STUPID HACK ALERT!!!! STUPID HACK ALERT!!!!!
50 // constype - the type of console to use (see enum ConsoleType)
51 // sparam - depending on the console type:
52 // TCP - the IP to bind to (127.0.0.1 if blank)
53 // Local - param ignored
54 // and for the iparam:
55 // TCP - the port to bind to
56 // Local - param ignored
57 // LogFile - duh
58 // componentname - which component of the OGS system? (user, asset etc)
59 // cmdparser - a reference to a conscmd_callback object
60
61 public MServerConsole(ConsoleType constype, string sparam, int iparam, string LogFile, string componentname, conscmd_callback cmdparser) {
62 ConsType = constype;
63 this.componentname = componentname;
64 this.cmdparser = cmdparser;
65 switch(constype) {
66 case ConsoleType.Local:
67 Console.WriteLine("ServerConsole.cs - creating new local console");
68 Console.WriteLine("Logs will be saved to current directory in " + LogFile);
69 Log=File.AppendText(LogFile);
70 Log.WriteLine("========================================================================");
71 Log.WriteLine(componentname + " " + VersionInfo.Version + " Started at " + DateTime.Now.ToString());
72 break;
73
74 case ConsoleType.TCP:
75 break;
76
77 default:
78 Console.WriteLine("ServerConsole.cs - what are you smoking? that isn't a valid console type!");
79 break;
80 }
81 }
82
83 public override void Close() {
84 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
85 Log.Close();
86 }
87
88 // You know what ReadLine() and WriteLine() do, right? And Read() and Write()? Right, you do actually know C#, right? Are you actually a programmer? Do you know english? Do you find my sense of humour in comments irritating? Good, glad you're still here
89 public override void WriteLine(string Line) {
90 Log.WriteLine(Line);
91 Console.WriteLine(Line);
92 return;
93 }
94
95 public override string ReadLine() {
96 string TempStr=Console.ReadLine();
97 Log.WriteLine(TempStr);
98 return TempStr;
99 }
100
101 public override int Read() {
102 int TempInt= Console.Read();
103 Log.Write((char)TempInt);
104 return TempInt;
105 }
106
107 public override void Write(string Line) {
108 Console.Write(Line);
109 Log.Write(Line);
110 return;
111 }
112
113
114 // Displays a prompt and waits for the user to enter a string, then returns that string
115 // Done with no echo and suitable for passwords
116 public override string PasswdPrompt(string prompt) {
117 // FIXME: Needs to be better abstracted
118 Log.WriteLine(prompt);
119 this.Write(prompt);
120 ConsoleColor oldfg=Console.ForegroundColor;
121 Console.ForegroundColor=Console.BackgroundColor;
122 string temp=Console.ReadLine();
123 Console.ForegroundColor=oldfg;
124 return temp;
125 }
126
127 // Displays a command prompt and waits for the user to enter a string, then returns that string
128 public override string CmdPrompt(string prompt) {
129 this.Write(prompt);
130 return this.ReadLine();
131 }
132
133 // Displays a command prompt and returns a default value if the user simply presses enter
134 public override string CmdPrompt(string prompt, string defaultresponse) {
135 string temp=CmdPrompt(prompt);
136 if(temp=="") {
137 return defaultresponse;
138 } else {
139 return temp;
140 }
141 }
142
143 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
144 public override string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) {
145 bool itisdone=false;
146 string temp=CmdPrompt(prompt,defaultresponse);
147 while(itisdone==false) {
148 if((temp==OptionA) || (temp==OptionB)) {
149 itisdone=true;
150 } else {
151 this.WriteLine("Valid options are " + OptionA + " or " + OptionB);
152 temp=CmdPrompt(prompt,defaultresponse);
153 }
154 }
155 return temp;
156 }
157
158 // Runs a command with a number of parameters
159 public override Object RunCmd(string Cmd, string[] cmdparams) {
160 cmdparser.RunCmd(Cmd, cmdparams);
161 return null;
162 }
163
164 // Shows data about something
165 public override void ShowCommands(string ShowWhat) {
166 cmdparser.Show(ShowWhat);
167 }
168
169 public override void MainConsolePrompt() {
170 string[] tempstrarray;
171 string tempstr = this.CmdPrompt(this.componentname + "# ");
172 tempstrarray = tempstr.Split(' ');
173 string cmd=tempstrarray[0];
174 Array.Reverse(tempstrarray);
175 Array.Resize<string>(ref tempstrarray,tempstrarray.Length-1);
176 Array.Reverse(tempstrarray);
177 string[] cmdparams=(string[])tempstrarray;
178 RunCmd(cmd,cmdparams);
179 }
180 }
181}
diff --git a/ogs/common/src/Util.cs b/ogs/common/src/Util.cs
new file mode 100644
index 0000000..1efa471
--- /dev/null
+++ b/ogs/common/src/Util.cs
@@ -0,0 +1,87 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Collections.Generic;
32using System.Threading;
33using libsecondlife;
34using libsecondlife.Packets;
35
36namespace OpenGridServices
37{
38 /// <summary>
39 /// </summary>
40 ///
41 public class Util
42 {
43 public static ulong UIntsToLong(uint X, uint Y)
44 {
45 return Helpers.UIntsToLong(X,Y);
46 }
47 public Util()
48 {
49
50 }
51 }
52
53 public class QueItem {
54 public QueItem()
55 {
56 }
57
58 public Packet Packet;
59 public bool Incoming;
60 }
61
62
63 public class BlockingQueue< T > {
64 private Queue< T > _queue = new Queue< T >();
65 private object _queueSync = new object();
66
67 public void Enqueue(T value)
68 {
69 lock(_queueSync)
70 {
71 _queue.Enqueue(value);
72 Monitor.Pulse(_queueSync);
73 }
74 }
75
76 public T Dequeue()
77 {
78 lock(_queueSync)
79 {
80 if( _queue.Count < 1)
81 Monitor.Wait(_queueSync);
82
83 return _queue.Dequeue();
84 }
85 }
86 }
87}
diff --git a/ogs/common/src/VersionInfo.cs.template b/ogs/common/src/VersionInfo.cs.template
new file mode 100644
index 0000000..8f73b4b
--- /dev/null
+++ b/ogs/common/src/VersionInfo.cs.template
@@ -0,0 +1,37 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*/
26
27using System;
28
29namespace OpenGridServices
30{
31 /// <summary>
32 /// </summary>
33 public class VersionInfo
34 {
35 public static string Version = "@@VERSION";
36 }
37}