Example #1
0
    public void SendWhisper(string whisperName, ChatServerClient client)
    {
        if (tickMessages.ChatDataPackages.Count > 0)
        {
            //DEBUG
            if (chatGUI != null)
            {
                foreach (var item in tickMessages.ChatDataPackages)
                {
                    chatGUI.chatHistorie.Add(item.PlayerName + " : " + item.port + " : " + item.Message + " : to: " + item.Target);
                }
            }


            byte[] mes = TCPHelper.MessageBytes(tickMessages);
            //skal finde playeren man whisper
            for (int i = 0; i < Clients.Count; i++)
            {
                if (Clients[i].clientName == whisperName)
                {
                    Clients[i].SendToClient(mes);
                    client.SendToClient(mes);
                }
            }
        }
    }
Example #2
0
 //join group
 public void JoinGroup(string groupName, ChatServerClient client)
 {
     for (int i = 0; i < ChatServer.groups.Count; i++)
     {
         if (ChatServer.groups[i].GroupName == groupName)
         {
             if (!ChatServer.groups[i].Members.Contains(client))
             {
                 ChatServer.groups[i].Members.Add(client);
             }
         }
     }
 }
Example #3
0
 // leave group
 public void LeaveGroup(string groupName, ChatServerClient client)
 {
     for (int i = 0; i < ChatServer.groups.Count; i++)
     {
         if (ChatServer.groups[i].GroupName == groupName)
         {
             ChatServer.groups[i].Members.Remove(client);
             var dasGroup = ChatServer.groups[i];
             var mes      = TCPHelper.MessageBytes(ChatServer.groups[i]);
             for (int y = 0; y < dasGroup.Members.Count; y++)
             {
                 dasGroup.Members[i].SendToClient(mes);
             }
         }
     }
 }
Example #4
0
 /// <summary>
 /// An endless coroutine which handles when new clients are connected,
 /// and instantiates internal clients on unity threads.
 /// </summary>
 /// <returns></returns>
 public IEnumerator WaitForClients()
 {
     while (true)
     {
         while (ChatServer.tcpClients.Count > 0)
         {
             if (ChatServer.tcpClients.TryDequeue(out TcpClient tcpClient))
             {
                 ChatServerClient client = new ChatServerClient(tcpClient);
                 ChatServer.Clients.Add(client);
                 StartCoroutine(client.ListenForMessages());
             }
         }
         yield return(null);
     }
 }
Example #5
0
        static void Main(string[] args)
        {
            string clienturl = new Random().Next(0, 1000).ToString(CultureInfo.InvariantCulture);

            const string callBackUrl = "http://localhost:1099/ChatClient/";

            string completeCallBackUrl = callBackUrl + clienturl;

            Console.WriteLine("URL = {0}", completeCallBackUrl);

            // Start Client Proxy
            var baseAddress = new Uri(completeCallBackUrl);
            var host = new ServiceHost(typeof(ChatClient), baseAddress);
            host.Open();

            using (var serverReference = new ChatServerClient())
            {
                Console.WriteLine("Introduza o utilizador:");
                string username = Console.ReadLine();
                Console.WriteLine("Introduza a palavra passe:");
                string pass = Console.ReadLine();

                serverReference.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:1337/ChatServer");

                if (serverReference.LogIn(completeCallBackUrl, username, pass))
                {
                    Console.WriteLine("Introduze a menssagem a enviar ou 'exit' para abandonar...");

                    var message = Console.ReadLine();

                    while (!string.IsNullOrEmpty(message) && !message.Equals("exit"))
                    {

                        // Send the message
                        serverReference.SendMessage(username, message);

                        message = Console.ReadLine();

                    }
                    serverReference.LogOut(username);
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            string clienturl = new Random().Next(0, 1000).ToString(CultureInfo.InvariantCulture);

            const string callBackUrl = "http://localhost:1099/ChatClient/";

            string completeCallBackUrl = callBackUrl + clienturl;

            Console.WriteLine("URL = {0}", completeCallBackUrl);

            // Start Client Proxy
            var baseAddress = new Uri(completeCallBackUrl);
            var host        = new ServiceHost(typeof(ChatClient), baseAddress);

            host.Open();

            using (var serverReference = new ChatServerClient())
            {
                Console.WriteLine("Introduza o utilizador:");
                string username = Console.ReadLine();
                Console.WriteLine("Introduza a palavra passe:");
                string pass = Console.ReadLine();

                serverReference.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:1337/ChatServer");

                if (serverReference.LogIn(completeCallBackUrl, username, pass))
                {
                    Console.WriteLine("Introduze a menssagem a enviar ou 'exit' para abandonar...");

                    var message = Console.ReadLine();

                    while (!string.IsNullOrEmpty(message) && !message.Equals("exit"))
                    {
                        // Send the message
                        serverReference.SendMessage(username, message);

                        message = Console.ReadLine();
                    }
                    serverReference.LogOut(username);
                }
            }
        }
Example #7
0
    //create group
    public void CreateGroup(string groupName, ChatServerClient client)
    {
        ChatGroup mygroup = new ChatGroup()
        {
            GroupName = groupName, ID = ChatServer.idNumber
        };

        ChatServer.idNumber += 1;
        bool exists = false;

        foreach (var item in groups)
        {
            if (item.GroupName == groupName)
            {
                exists = true;
                break;
            }
        }

        if (!exists)
        {
            ChatServer.groups.Add(mygroup);
        }



        //client.SendMessage("Group create: " + groupName);
        //DEBUG
        if (chatGUI != null)
        {
            foreach (var item in tickMessages.ChatDataPackages)
            {
                chatGUI.chatHistorie.Add(groupName + " created");
            }
        }
        JoinGroup(groupName, client);
    }
Example #8
0
 public static void Disconnect(ChatServerClient disconnectedClient)
 {
     Clients.Remove(disconnectedClient);
 }