Ejemplo n.º 1
0
 protected void SendConnectionAcceptEvent()
 {
     EventHandler<WCServerClientEventArgs> handler = Connected;
     String connectMsg = "***" + Username + " has connected.";
     IWCMessage message = new WCMessage(connectMsg, WCMessageType.SERVER);
     if (handler != null)
     {
         handler(this, new WCServerClientEventArgs(ClientID, Username, message));
     }
 }
Ejemplo n.º 2
0
 public void Test_GetBytes_SingleMessage()
 {
     string teststr = "test msg";
     IWCMessage test_textmsg = new WCMessage(teststr, WCMessageType.MESSAGE);
     BinaryNetworkAdapter nAdapter = new BinaryNetworkAdapter();
     var testdata = nAdapter.GetBytes(test_textmsg);
     List<IWCMessage> messages = (List<IWCMessage>)nAdapter.CreateMessages(testdata);
     Assert.IsTrue(messages.Count == 1, "Message count is not 1");
     IWCMessage received_msg = messages[0];
     Assert.IsTrue(received_msg.Message.Equals(teststr), "message text is not equal");
     Assert.IsTrue(received_msg.MessageType == WCMessageType.MESSAGE, "message type is not equal");
 }
Ejemplo n.º 3
0
 public override void Stop(String shutDownText)
 {
     listener.Stop();
     Running = false;
     String str = "***Server is shutting down. Reason ( ";
     IWCMessage message = new WCMessage(str + shutDownText + " )", WCMessageType.DISCONNECT);
     foreach (var client in clients.Values)
     {
         client.CommunicationChannel.SendMessage(message);
         client.CommunicationChannel.Disconnect(false);
     }
 }
Ejemplo n.º 4
0
 public void SendMessage(String message)
 {
     if (message == null || connected < 1)
     {
         return;
     }
     if (message[0] == '/')
     {
         Disconnect("Quitting");
     }
     else
     {
         IWCMessage msgToSend = new WCMessage(message, WCMessageType.MESSAGE);
         client.SendMessage(msgToSend);
     }
 }
Ejemplo n.º 5
0
 public void Test_GetBytes_MultiMessage()
 {
     string teststr1 = "test msg1";
     string teststr2 = "test msg2";
     IWCMessage test_textmsg1 = new WCMessage(teststr1, WCMessageType.MESSAGE);
     IWCMessage test_textmsg2 = new WCMessage(teststr2, WCMessageType.SERVER);
     BinaryNetworkAdapter nAdapter = new BinaryNetworkAdapter();
     var testdata1 = nAdapter.GetBytes(test_textmsg1);
     var testdata2 = nAdapter.GetBytes(test_textmsg2);
     var data = new byte[testdata1.Length + testdata2.Length];
     Array.Copy(testdata1, 0, data, 0, testdata1.Length);
     Array.Copy(testdata2, 0, data, testdata1.Length, testdata2.Length);
     List<IWCMessage> messages = (List<IWCMessage>)nAdapter.CreateMessages(data);
     Assert.IsTrue(messages.Count == 2, "Message count is not 2");
     IWCMessage received_msg1 = messages[0];
     Assert.IsTrue(received_msg1.Message.Equals(teststr1), "message text is not equal");
     Assert.IsTrue(received_msg1.MessageType == WCMessageType.MESSAGE, "message type is not equal");
     IWCMessage received_msg2 = messages[1];
     Assert.IsTrue(received_msg2.Message.Equals(teststr2), "message text is not equal");
     Assert.IsTrue(received_msg2.MessageType == WCMessageType.SERVER, "message type is not equal");
 }
Ejemplo n.º 6
0
 protected void HandleConnectionRequest(IWCMessage message)
 {
     if (pendingAuth)
     {
         if (message.Message.Length > 0)
         {
             Username = message.Message;
             pendingAuth = false;
             SendConnectionAcceptEvent();
         }
         else
         {
             IWCMessage denyMessage = new WCMessage("Connection Refused: Username was empty.", WCMessageType.CONNECTDENY);
             SendConnectionDenyEvent(denyMessage);
             Debug.WriteLine("HandleConnectioRequest() failed due to message.legnth not greater then 0");
         }
     }
     else
     {
         Debug.WriteLine("HandleConnectioRequest() failed due to pendingAuth = false");
     }
 }
Ejemplo n.º 7
0
 protected void SendDisconnectEvent(IWCMessage message)
 {
     EventHandler<WCServerClientEventArgs> handler = Disconnected;
     String disconnectMsg = "***" + Username + " has disconnected ( " + message.Message + " )";
     IWCMessage discoMessage = new WCMessage(disconnectMsg, WCMessageType.SERVER);
     if (handler != null)
     {
         handler(this, new WCServerClientEventArgs(ClientID, Username, discoMessage));
     }
 }
Ejemplo n.º 8
0
 public void Disconnect(String reason)
 {
     IWCMessage message = new WCMessage(reason, WCMessageType.DISCONNECT);
     client.Disconnect(message);
     connected = -1;
 }