/// <summary>
        /// Processes an unconnected client's request to connect to the server for the first time.
        /// </summary>
        private void processClientConnectRequest(IncomingMessage incomingMessage, IPEndPoint endPoint)
        {
            if (incomingMessage.BytesLeft < 9)
            {
                return;
            }

            int    clientAppIDHash      = incomingMessage.ReadInt32();
            int    clientMaxMessageSize = incomingMessage.ReadInt32();
            string clientName           = incomingMessage.ReadString();

            int nextClientID = this.getNextAvailableClientID();

            if (clientAppIDHash != ReaderWriterHelper.GetStringHash(this.ApplicationID) || clientMaxMessageSize != this.MaxMessageSize)
            {
                // Client is using a different app, reject
                this.sendConnectResponse(endPoint, 0, PacketTypeDetail.ConnectResponseRejectAppMismatch);
            }
            else if (nextClientID < 0)
            {
                // Server is full, reject
                this.sendConnectResponse(endPoint, 0, PacketTypeDetail.ConnectResponseRejectServerFull);
            }
            else
            {
                this.clients[nextClientID].SetStateAwaitingConnectFinalize(endPoint, this.NetworkTick);
                this.endPointToClientID[endPoint] = nextClientID;
                this.sendConnectResponse(endPoint, (byte)nextClientID, PacketTypeDetail.ConnectResponseAccept);
            }
        }
 /// <summary>
 /// Immediately sends a packet to the given end point in response to a connection request.
 /// </summary>
 private void sendConnectRequest(PacketType packetType, PacketTypeDetail packetTypeInfo)
 {
     this.outgoingMessage.Reset();
     this.outgoingMessage.Write((byte)packetType);
     this.outgoingMessage.Write((byte)packetTypeInfo);
     this.outgoingMessage.Write(ReaderWriterHelper.GetStringHash(this.ApplicationID));
     this.outgoingMessage.Write(this.MaxMessageSize);
     this.outgoingMessage.Write("No name");
     ((INetworkConnection)this).SendMessage(this.outgoingMessage);
 }
 /// <summary>
 /// Immediately sends a packet to the given end point in response to a connection request.
 /// </summary>
 private void sendConnectResponse(IPEndPoint toEndPoint, byte clientID, PacketTypeDetail packetTypeInfo)
 {
     this.outgoingMessage.Reset();
     this.outgoingMessage.Write((byte)PacketType.ServerConnectResponse);
     this.outgoingMessage.Write((byte)packetTypeInfo);
     this.outgoingMessage.Write(clientID);
     this.outgoingMessage.Write(ReaderWriterHelper.GetStringHash(this.ApplicationID));
     this.outgoingMessage.Write(this.MaxMessageSize);
     ((INetworkConnection)this.clients[clientID]).SendMessage(this.outgoingMessage);
 }