Ejemplo n.º 1
0
 /// <summary>
 /// Will ban a given user with optional reason
 /// </summary>
 /// <param name="cc"></param>
 /// <param name="reason"></param>
 public void Ban(ChatClient cc, string reason="banned from server")
 {
     bans.Add(cc.GetBase());
     Kick(cc, reason);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// A client requested unban of another client
 /// </summary>
 /// <param name="me"></param>
 /// <param name="target"></param>
 void c_UnbanRequest(ChatClient me, Common.ChatClientWrapper target)
 {
     if (me.PermLevel < 2)
     {
         me.SendError("no permissions");
         return;
     }
     string targetUID = target.UniqueID;
     Common.ChatClientWrapper targ = null;
     foreach (Common.ChatClientWrapper cc in bans)
         if (cc.UniqueID == targetUID)
             targ = cc;
     if (targ == null)
         me.SendError("invalid client");
     else
     {
         bans.Remove(targ);
         UnbanEvent.Invoke(me, targ);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// The Thread that will keep accepting Tcp Clients
 /// </summary>
 private void ListenThread()
 {
     while (true)
     {
         try
         {
             foreach (TcpListener l in listeners)
                 while (l.Pending())
                 {
                     ChatClient c = new ChatClient(l.AcceptTcpClient(), "", "", 0, false);
                     c.AuthenticatedEvent += c_AuthenticatedEvent;
                     c.DisconnectedEvent += c_DisconnectedEvent;
                     c.GlobalMessageEvent += c_GlobalMessageEvent;
                     c.ClientListRequest += c_ClientListRequest;
                     c.BanListRequest += c_BanListRequest;
                     c.KickRequest += c_KickRequest;
                     c.BanRequest += c_BanRequest;
                     c.UnbanRequest += c_UnbanRequest;
                     c.PrivateMessageEvent += c_PrivateMessageEvent;
                     clients.Add(c);
                 }
         }
         catch (ThreadAbortException) { break; }
         catch (Exception) { }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// A client-side Kick request
        /// </summary>
        /// <param name="me"></param>
        /// <param name="target"></param>
        void c_KickRequest(ChatClient me, Common.ChatClientMessageWrapper target)
        {
            if(me.PermLevel < 1) {
                me.SendError("no permissions");
                return;
            }

            string targetUID = target.UniqueID;
            ChatClient targ = null;
            foreach (ChatClient cc in clients)
                if (cc.UniqueID == targetUID)
                    targ = cc;
            if (targ == null)
                me.SendError("invalid client");
            else
                Kick(targ, target.Message);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Client requests Private Message to another client
 /// </summary>
 /// <param name="me"></param>
 /// <param name="target"></param>
 void c_PrivateMessageEvent(ChatClient me, Common.ChatClientMessageWrapper target)
 {
     string targetUID = target.UniqueID;
     ChatClient targ = null;
     foreach (ChatClient cc in clients)
         if (cc.UniqueID == targetUID)
             targ = cc;
     if (targ == null)
         me.SendError("invalid client");
     else
     {
         Common.ChatClientMessageWrapper ccmw = new Common.ChatClientMessageWrapper(me.GetBase(), target.Message);
         targ.PrivateMessage(ccmw);
         PrivateMessageEvent.Invoke(me, targ);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Client Disconnected for whatever reason
 /// </summary>
 /// <param name="me"></param>
 /// <param name="s"></param>
 void c_DisconnectedEvent(ChatClient me, string s)
 {
     DisconnectedEvent.Invoke(me, s);
     foreach (ChatClient cc in clients)
     {
         cc.ClientLeft(me.GetBase());
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// A client sent a public chatmessage
 /// </summary>
 /// <param name="me"></param>
 /// <param name="s"></param>
 void c_GlobalMessageEvent(ChatClient me, string s)
 {
     GlobalMessageEvent.Invoke(me, s);
     Common.ChatClientMessageWrapper ccmw = new Common.ChatClientMessageWrapper(me.GetBase(), s);
     foreach (ChatClient cc in clients)
     {
         cc.PublicMessage(ccmw);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Client requested Client List
 /// </summary>
 /// <param name="me"></param>
 void c_ClientListRequest(ChatClient me)
 {
     Common.ChatClientListWrapper send = new Common.ChatClientListWrapper();
     send.List.AddRange(clients);
     me.SendClientList(send);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Client requests ban-list
 /// </summary>
 /// <param name="me"></param>
 void c_BanListRequest(ChatClient me)
 {
     if (me.PermLevel < 2) {
         me.SendError("no permissions");
         return;
     }
     Common.ChatClientListWrapper send = new Common.ChatClientListWrapper();
     send.List.AddRange(bans);
     me.SendbanList(send);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Client Successfully authenticated as client
 /// </summary>
 /// <param name="me"></param>
 void c_AuthenticatedEvent(ChatClient me)
 {
     AuthenticatedEvent.Invoke(me);
     foreach (ChatClient cc in clients)
     {
         cc.ClientJoined(me.GetBase());
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Disconnects a client with optional reason
 /// </summary>
 /// <param name="cc"></param>
 /// <param name="reason"></param>
 public void Kick(ChatClient cc, string reason="kicked from server")
 {
     clients.Remove(cc);
     cc.AuthenticatedEvent -= c_AuthenticatedEvent;
     cc.DisconnectedEvent -= c_DisconnectedEvent;
     cc.GlobalMessageEvent -= c_GlobalMessageEvent;
     cc.ClientListRequest -= c_ClientListRequest;
     cc.BanListRequest -= c_BanListRequest;
     cc.KickRequest -= c_KickRequest;
     cc.BanRequest -= c_BanRequest;
     cc.UnbanRequest -= c_UnbanRequest;
     cc.PrivateMessageEvent -= c_PrivateMessageEvent;
     cc.Disconnect(reason);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Used to call an client-update if permissions were changed
 /// </summary>
 /// <param name="cc"></param>
 public void ClientUpdate(ChatClient me)
 {
     foreach (ChatClient cc in clients)
     {
         cc.ClientUpdate(me.GetBase());
     }
 }