Esempio n. 1
0
        /// <summary>
        /// Log an error message.
        /// </summary>

        public void Log(string msg, string stack = null, bool logInFile = true)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(name);
            sb.Append(" (");
            sb.Append(address);

            if (aliases != null)
            {
                for (int i = 0; i < aliases.size; ++i)
                {
                    sb.Append(", " + aliases.buffer[i]);
                }
            }

            sb.Append("): ");
            sb.Append(msg);

            if (stack != null)
            {
                sb.Append("\n");
                sb.Append(stack);
            }
            Tools.Log(sb.ToString(), logInFile);
        }
Esempio n. 2
0
        /// <summary>
        /// Verify the connection. Returns 'true' if successful.
        /// </summary>

        public bool VerifyRequestID(BinaryReader reader, Buffer buffer, bool uniqueID)
        {
            Packet request = (Packet)reader.ReadByte();

            if (request == Packet.RequestID)
            {
                int theirVer = reader.ReadInt32();

                if (theirVer == version)
                {
                    if (uniqueID)
                    {
                        lock (mLock) { id = ++mPlayerCounter; }
                    }
                    else
                    {
                        id = 0;
                    }
                    name     = reader.ReadString();
                    dataNode = reader.ReadDataNode();
                    stage    = TcpProtocol.Stage.Connected;
#if STANDALONE
                    if (id != 0)
                    {
                        Tools.Log(name + " (" + address + "): Connected [" + id + "]");
                    }
#endif
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Remove the specified keyword from the ban list.
        /// </summary>

        public virtual void Unban(string keyword)
        {
            if (string.IsNullOrEmpty(keyword))
            {
                return;
            }

            if (mBan.Remove(keyword))
            {
                Tools.Log("Removed a banned keyword (" + keyword + ")");
                SaveBanList();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add the specified keyword to the ban list.
        /// </summary>

        public virtual void Ban(string keyword)
        {
            if (string.IsNullOrEmpty(keyword))
            {
                return;
            }

            if (!mBan.Contains(keyword))
            {
                mBan.Add(keyword);
                Tools.Log("Added a banned keyword (" + keyword + ")");
                SaveBanList();
            }
            else
            {
                Tools.Log("Ban already exists (" + keyword + ")");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Close the connection.
        /// </summary>

        void CloseNotThreadSafe(bool notify)
        {
#if !MODDING
#if STANDALONE || UNITY_EDITOR
            if (id != 0)
            {
                Tools.Log(name + " (" + address + "): Disconnected [" + id + "]");
            }
#endif
            Buffer.Recycle(mOut);
            stage    = Stage.NotConnected;
            mSending = false;

            if (mSocket != null || custom != null)
            {
                if (mSocket != null)
                {
                    try
                    {
                        if (mSocket.Connected)
                        {
                            mSocket.Shutdown(SocketShutdown.Both);
                        }
                        mSocket.Close();
                    }
                    catch (System.Exception) { }
                    mSocket = null;
                }

                if (custom != null)
                {
                    custom.OnDisconnect();
                }

                if (notify)
                {
                    var buffer = Buffer.Create();
                    buffer.BeginPacket(Packet.Disconnect);
                    buffer.EndTcpPacketWithOffset(4);

                    lock (mIn)
                    {
                        Buffer.Recycle(mIn);
                        mIn.Enqueue(buffer);
                    }
                }
                else
                {
                    lock (mIn) Buffer.Recycle(mIn);
                }
            }
            else if (notify && sendQueue != null)
            {
                sendQueue = null;
                Buffer buffer = Buffer.Create();
                buffer.BeginPacket(Packet.Disconnect);
                buffer.EndTcpPacketWithOffset(4);

                lock (mIn)
                {
                    Buffer.Recycle(mIn);
                    mIn.Enqueue(buffer);
                }
            }

            if (mReceiveBuffer != null)
            {
                mReceiveBuffer.Recycle();
                mReceiveBuffer = null;
            }

            if (onClose != null)
            {
                onClose(this);
            }

            id = 0;
#endif
        }