コード例 #1
0
    void Start()
    {
        Instance = this;

        inputFieldObj     = GameObject.Find("CommandInputField");
        CommandInputField = inputFieldObj.GetComponent <InputField>();

        CommandInputField.Select();
        CommandInputField.ActivateInputField();

        CommandDelegates = new Dictionary <string, CommandDelegate>();
        commandManager   = new CommandManager();
        SocketCommands   = new SocketCommands(transform.GetComponent <ServerObj>());

        CommandBuffer            = new LinkedList <string>();
        CommandBufferSearchIndex = null;
    }
コード例 #2
0
ファイル: Server.cs プロジェクト: Aizhuldyz/MentoringL2
        private static void AcceptServiceCallback(IAsyncResult ar)
        {
            Socket socket;

            try
            {
                socket = ServiceSocket.EndAccept(ar);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            var clientSocket = SocketCommands.Read(socket);

            clientSocket.Message = _chatHistoryFixedSizedQueue.ToList();
            clientSocket.Guid    = Guid.NewGuid();
            SocketCommands.Write(socket, clientSocket);
            ServiceSocket.BeginAccept(AcceptServiceCallback, null);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Aizhuldyz/MentoringL2
 private static void MessageReadCallback()
 {
     while (true)
     {
         if (_client.Guid != Guid.Empty && MessageSocket.Connected)
         {
             try
             {
                 var socketModel = SocketCommands.Read(MessageSocket);
                 foreach (var message in socketModel.Message)
                 {
                     Console.WriteLine(socketModel.Name + ":" + message);
                 }
             }
             catch (SocketException)
             {
                 Exit();
             }
         }
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: Aizhuldyz/MentoringL2
 private static void MessageWriteCallback()
 {
     while (true)
     {
         var socketMessage = new SocketClient
         {
             Name    = _client.Name,
             Guid    = _client.Guid,
             Message = new List <string>()
         };
         socketMessage.Message.Add(
             MessageList.ElementAt(new Random().Next(0, MessageList.Count - 1)));
         try
         {
             SocketCommands.Write(MessageSocket, socketMessage);
         }
         catch (SocketException)
         {
             Exit();
         }
         Thread.Sleep(BetweenMessagePauseTime);
     }
 }
コード例 #5
0
ファイル: Server.cs プロジェクト: Aizhuldyz/MentoringL2
        private static void ReceiveCallback(IAsyncResult ar)
        {
            SocketServer current = (SocketServer)ar.AsyncState;
            int          received;

            try
            {
                received = current.Socket.EndReceive(ar);
            }
            catch (SocketException)
            {
                Console.WriteLine("Client forcefully disconnected");
                // Don't shutdown because the socket may be disposed and its disconnected anyway.
                current.Socket.Close();
                var index = ClientSockets.FindIndex(x => x.Socket == current.Socket);
                ClientSockets.RemoveAt(index);
                return;
            }
            var data = new byte[received];

            Array.Copy(current.Buffer, data, received);
            var socketModel = (SocketClient)SocketCommands.ByteArrayToObject(data);

            foreach (var message in socketModel.Message)
            {
                _chatHistoryFixedSizedQueue.Enqueue(socketModel.Name + ": " + message);
            }
            foreach (var client in ClientSockets)
            {
                if (client.Socket != current.Socket)
                {
                    var message = SocketCommands.ObjectToByteArray(socketModel);
                    client.Socket.Send(message);
                }
            }
            current.Socket.BeginReceive(current.Buffer, 0, BufferSize, SocketFlags.None, ReceiveCallback, current);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Aizhuldyz/MentoringL2
        private static void ConnectServiceCallback(IAsyncResult ar)
        {
            try
            {
                ServiceSocket.EndConnect(ar);
                MessageSocket.BeginConnect(IPAddress.Loopback, MessagePort, ConnectMessageCallback, null);
            }
            catch (SocketException)
            {
                Console.WriteLine("Connection was not established!");
            }

            Console.WriteLine("ServiceSocket Connected");
            SocketCommands.Write(ServiceSocket, _client);
            while (_client.Guid == Guid.Empty)
            {
                var socketModel = SocketCommands.Read(ServiceSocket);
                _client.Guid = socketModel.Guid;
                foreach (var message in socketModel.Message)
                {
                    Console.WriteLine(message);
                }
            }
        }
コード例 #7
0
 public SocketCommand(SocketCommands cmd, SocketCommandData met)
 {
     Command  = cmd;
     Metadata = met;
 }
コード例 #8
0
 public SocketCommand(SocketCommands cmd)
 {
     Command = cmd;
 }
コード例 #9
0
 public SocketCommand(SocketCommands cmd, object[] data)
 {
     _command   = cmd;
     _extraData = data;
 }
コード例 #10
0
 private static object SendCommand(SocketCommands cmd, ulong OriginClientId = 0)
 {
     return(new SocketMessage(OriginClientId, new SocketCommand(cmd)));
 }
コード例 #11
0
            // ??? Use this Socket xx, ClientSocket xx in parameters
            //Not neccesary to get byte[], ... also, I will move this to new class called SocketHandler, Deserialize and Serialize not needed anymore

            //Reimplement here serialize / deserialize functions?

            //0 means that the message is not for any client, is a broadcast message sended to the server, so, we have to handle errors when we don't manage it correctly.
            public static object SendCommand(SocketCommands cmd, SocketCommandData data, ulong OriginClientId = 0)
            {
                return(new SocketMessage(OriginClientId, new SocketCommand(cmd, data)));
            }
コード例 #12
0
ファイル: SocketCommand.cs プロジェクト: andy012345/WoWServer
 public SocketCommand(SocketCommands cmd, object[] data)
 {
     _command = cmd;
     _extraData = data;
 }
コード例 #13
0
ファイル: SocketCommand.cs プロジェクト: andy012345/WoWServer
 public SocketCommand(SocketCommands cmd)
 {
     _command = cmd;
 }