private TAClientListener(TAServer server)
 {
     this.server = server;
     TAServerLog.log("Listening for clients...", LogType.SERVER_ACTION);
     clientListener = new TcpListener(WebsocketUtility.getLocalIP(), TAServer.CLIENT_LISTEN_PORT);
     clientListener.Start();
     listening = true;
 }
示例#2
0
        public void receiveMessage(Byte[] data, TAClient sender)
        {
            TAServerLog.log("RX msg from client: " + sender.clientName + ", ID: " + sender.clientID + " at " + DateTime.Now, LogType.CLIENT_MESSAGE_RX);
            Byte[] decodedMsg    = WebsocketUtility.decodeWebsocketMessage(data);
            string messageString = Encoding.UTF8.GetString(decodedMsg);

            sender.parseMessage(messageString);
            //do whatever with the message string from here
        }
示例#3
0
        public void addClient(TcpClient c)
        {
            var newClient = TAClient.createClient(this, c);

            clients.Add(newClient);
            TAServerLog.log("Added new client: " + newClient.clientName + ", ID: " + newClient.clientID + " at " + DateTime.Now, LogType.CLIENT_MESSAGE_RX);
            sendSelectiveStory("Welcome to the server!", newClient.clientName + " has joined the server!", newClient);
            newClient.locationUpdate();
            sendProgressBarEntry("Loading Character!", 100, newClient);
        }
        public override void doOption()
        {
            Console.WriteLine("Who would you like to kick? Enter the player ID.");
            foreach (var p in serverInterface.server.clients)
            {
                Console.WriteLine(p.clientName + ", ID: " + p.clientID + "\n");
            }
            string targetID = Console.ReadLine();

            foreach (var p in serverInterface.server.clients)
            {
                if (Convert.ToInt32(targetID) == p.clientID)
                {
                    p.stopClient();
                    TAServerLog.log(p.clientName + " was kicked from the server", LogType.PLAYER_KICKED);
                    return;
                }
            }
            Console.WriteLine("No player was found matching that ID.");
        }
示例#5
0
 private void sendMessage(string msgStr, params TAClient[] targets)
 {
     Byte[] data           = Encoding.UTF8.GetBytes(msgStr);
     Byte[] encodedMessage = WebsocketUtility.encodeWebsocketMessage(data);
     foreach (var c in targets)
     {
         try
         {
             if (c.clientStream.CanWrite)
             {
                 c.clientStream.Write(encodedMessage, 0, encodedMessage.Length);
             }
             else
             {
                 Console.WriteLine("could not write to client stream");
             }
         }
         catch (System.IO.IOException e)
         {
             TAServerLog.log("Send message Failed: " + e.Message, LogType.ERROR);
         }
     }
 }