예제 #1
0
        private void _onConnectCallback(IAsyncResult pAsyncResult)
        {
            lock (__sysQueueLock)
            {
                try
                {
                    TcpClient pTCPClient = pAsyncResult.AsyncState as TcpClient;

                    Debugger.Assert(System.Object.ReferenceEquals(pTCPClient, _tcpClient));
                    pTCPClient.EndConnect(pAsyncResult);

                    _tcpClient.NoDelay = true;

                    _bIsNetDown = false;
                    __error     = null;

                    _receiveThread = new Thread(new ParameterizedThreadStart(_receiveThreadFunc));
                    _receiveThread.IsBackground = true;
                    _receiveThread.Start(_tcpClient.GetStream());

                    _sendThread = new Thread(new ParameterizedThreadStart(_sendThreadFunc));
                    _sendThread.IsBackground = true;
                    _sendThread.Start(_tcpClient.GetStream());

                    _SysMsg sysMsg = new _SysMsg(_SysMsgType.Connected);
                    __sysMsgQueue.Enqueue(sysMsg);
                }
                catch (Exception e)
                {
                    _SysMsg errMsg = new _SysMsg(_SysMsgType.ConnectFailed, e);
                    __sysMsgQueue.Enqueue(errMsg);
                }
            }
        }
예제 #2
0
    /// <summary>
    public void BackToState(int destState, object beginParams)
    {
        /// End current state
        FSMState popped = _stateStack.Pop();

        popped.Exit();

        bool bFind = false;

        /// Seek the suitable state
        while (_stateStack.Count != 0)
        {
            FSMState curState = _stateStack.Peek();

            if (curState.stateType == (int)destState)
            {
                if (OnBackState != null)
                {
                    OnBackState(destState);
                }

                curState.Entry(beginParams);
                bFind = true;
                ///Debugger.Log("Pop state from " + popped + " to " + curState);
                break;
            }
            else
            {
                _stateStack.Pop();
            }
        }

        Debugger.Assert(bFind, "DoBackToState failed, no state of type " + destState + "in the stack!");
    }
예제 #3
0
    /// Note: byte is uint8
    public void WriteByte(byte data)
    {
        Debugger.Assert(_iCurosr + 1 <= _nSize);

        _buffer[_iCurosr] = data;
        _iCurosr++;
    }
        private void InitMiscTab()
        {
            Debugger.Assert(
                () =>
            {
                Translation.AddTranslatableControl(tabPage_misc);

                // Propensity
                Translation.AddTranslatableControl(groupBox_propensity);
                string key;
                for (Propensity e = Propensity.Null + 1; e < EnumHelper.MaxPropensity; e++)
                {
                    key   = EnumHelper.GetName(e);
                    int i = checkedListBox_propensity.Items.Add(key, false);
                    Translation.AddTranslationAction(key, s => checkedListBox_propensity.Items[i] = s);
                }
                checkedListBox_propensity.Height = checkedListBox_propensity.ItemHeight
                                                   * checkedListBox_propensity.Items.Count;
                checkedListBox_propensity.ItemCheck += OnPropensityChecked;

                // Features
                Translation.AddTranslatableControl(groupBox_feature);
                for (Feature e = Feature.Null + 1; e < EnumHelper.MaxFeature; e++)
                {
                    key   = EnumHelper.GetName(e);
                    int i = checkedListBox_feature.Items.Add(key, false);
                    Translation.AddTranslationAction(key, s => checkedListBox_feature.Items[i] = s);
                }
                checkedListBox_feature.Height     = checkedListBox_feature.ItemHeight * checkedListBox_feature.Items.Count;
                checkedListBox_feature.ItemCheck += OnFeatureChecked;
            },
                "Failed to initialize propensity/feature tab");
        }
예제 #5
0
    public void Disconnect()
    {
        if (_connectionState == ConnectionState.DISCONNECTED)
        {
            return;
        }

        lock (__lock)
        {
            if (_networkStream != null)
            {
                _networkStream.Close();
                _networkStream = null;
            }

            Debugger.Assert(_tcpClient != null);
            _tcpClient.Close();
            _tcpClient = null;

            _heartBeatTimer.Stop();
            _bInUpdateSessionKey = false;

            __nBytesReceived     = 0;
            __bIsReceivingHeader = true;
            __bInWriting         = false;

            __sendMsgQueue.Clear();

            _connectionState = ConnectionState.DISCONNECTED;
        }
    }
예제 #6
0
    private void _onUpdateSessionKey(byte[] encryptedSessionKey)
    {
        byte[] rawSessionKey  = _deCodeSessionKey(encryptedSessionKey);
        byte[] realSessionKey = new byte[MsgBase.SESSION_KEY_SIZE];

        Buffer.BlockCopy(rawSessionKey, MsgBase.SESSION_KEY_HEAD_PADDING, realSessionKey, 0, MsgBase.SESSION_KEY_SIZE);

        _sessionKey          = realSessionKey;
        _encryptedSessionKey = null;

        _recreateEncryptionObjs(_sessionKey);

        Debugger.Log("Session key updated.......................");

        if (_connectionState == ConnectionState.CONNECTED)
        {
            _connectionState = ConnectionState.VALIDATED;

            _heartBeatTimer.Start();

            /// Dispatch connected message
            MsgBase pConnectedMsg = new MsgBase((int)SocketMsgTypes.SOCKET_VALIDATED);
            __receiveMsgQueue.Add(pConnectedMsg);
        }

        Debugger.Assert(_bInUpdateSessionKey);
        _bInUpdateSessionKey = false;
    }
예제 #7
0
    private void _processMessageData()
    {
        Debugger.Assert(__nMsgLength != 0);

        bool bNeedFurtherProcessing = _pConnectionHost.ReceivingFilter(__receiveBuffer, __nMsgLength);

        if (!bNeedFurtherProcessing)
        {
            return;
        }

        /// Mono has a bug on AES. Must recreate transform object each time.
        if (_pDecryptor != null)
        {
            _pDecryptor.Dispose();
        }
        _pDecryptor = _pAESMgr.CreateDecryptor();

        /// Check AES blocks size
        Debugger.Assert((__nMsgLength - MsgBase.HEAD_LENGTH) % 16 == 0);

        byte[] bytesDecoded = _pDecryptor.TransformFinalBlock(__receiveBuffer, MsgBase.HEAD_LENGTH
                                                              , __nMsgLength - MsgBase.HEAD_LENGTH);

        ByteBuffer pByteBuffer = new ByteBuffer(bytesDecoded);

        //get message meta
        byte   encodeType = pByteBuffer.FReadByte();
        int    nMessageID = pByteBuffer.FReadInt();
        ushort sCheckCode = pByteBuffer.FReadUShort();
        int    nTimestamp = pByteBuffer.FReadInt();

        //get message body
        byte[] bodyBytes = pByteBuffer.FReadBytes(pByteBuffer.size - MsgBase.META_DATA_LENGTH);

        Debugger.Assert(_pConnectionHost.ContainsServerMsgID(nMessageID));

        ///...Debugger.Assert(_isValidMsgFormat());

        if (nMessageID == SERVER_SESSION_UPDATE_KEY)
        {
            /// Update local time stamp
            _nLastSvrTime   = nTimestamp;
            _nLastLocalTime = NetworkStub.CurrentTimeSeconds();

            /// process session key
            _onUpdateSessionKey(bodyBytes);
        }
        else
        {
            /// Process normal message
            MsgBase message = new MsgBase(nMessageID);
            message.timeStamp = nTimestamp;
            Debugger.Assert(message.type != SERVER_SESSION_UPDATE_KEY);

            message.DeserializeFrom(bodyBytes);

            __receiveMsgQueue.Add(message);
        }
    }
예제 #8
0
    public void WriteBytes(byte[] data)
    {
        Debugger.Assert(_iCurosr + data.Length <= _nSize);

        Buffer.BlockCopy(data, 0, _buffer, _iCurosr, data.Length);
        _iCurosr += data.Length;
    }
예제 #9
0
        public ByteBuffer Serialize(int reservedSize, Func <int, ByteBuffer> bufferCreator)
        {
            byte[] clsNameBytes = Encoding.UTF8.GetBytes(_object.GetType().FullName);
            Debugger.Assert(clsNameBytes.Length <= 256);

            byte[] bytes = ProtoBufUtil.Serialize(_object);

            /// Calculate total length count
            int totalLen = reservedSize + (1 + clsNameBytes.Length) + (2 + bytes.Length);

            Debugger.Assert(totalLen <= ushort.MaxValue);

            /// Write to buffer
            ByteBuffer buffer = bufferCreator(totalLen);

            buffer.position = buffer.position + reservedSize;

            buffer.WriteByte((byte)clsNameBytes.Length);
            buffer.WriteBytes(clsNameBytes);

            buffer.WriteUShort((ushort)bytes.Length);
            buffer.WriteBytes(bytes);

            return(buffer);
        }
        private void OnFeaturePropensityUpdated(object sender, UpdateFeaturePropensityEventArgs args)
        {
            Debugger.Assert(
                () =>
            {
                MaidInfo maid = SelectedMaid;
                if (maid == null)
                {
                    return;
                }

                if (args.CallerMaid != maid.Maid)
                {
                    return;
                }

                if (args.UpdateFeature)
                {
                    Debugger.WriteLine(LogLevel.Info, "Updating all features!");
                    for (Feature e = Feature.Null + 1; e < EnumHelper.MaxFeature; e++)
                    {
                        maid.UpdateMiscStatus(MaidChangeType.Feature, (int)e);
                    }
                }
                else if (args.UpdatePropensity)
                {
                    Debugger.WriteLine(LogLevel.Info, "Updating all propensities!");
                    for (Propensity e = Propensity.Null + 1; e < EnumHelper.MaxPropensity; e++)
                    {
                        maid.UpdateMiscStatus(MaidChangeType.Propensity, (int)e);
                    }
                }
            },
                "Failed to update maid features/propensities");
        }
예제 #11
0
 /// Remove a manual tickable object.
 /// A manual tickable object must be add/remove by AddTickable/RemoveTickable.
 public void RemoveTickable(Tickable pTickable)
 {
     pTickable.Stop();
     pTickable.DecRef();
     _nManualTickersCount--;
     Debugger.Assert(_nManualTickersCount >= 0);
 }
예제 #12
0
    public int SerializeTo(byte[] buffer, ICryptoTransform pEncryptor, int nTimeStamp)
    {
        string strBodyString = _sendBody != null?JsonWriter.Serialize(_sendBody) : "{}";

        byte[] bodyBytes = Encoding.UTF8.GetBytes(strBodyString);

        int nContentLength = (ushort)bodyBytes.Length;

        Debugger.Assert(nContentLength <= MsgBase.MAX_CONTENT_LENGTH);

        /// Create body (Meta + Content)
        this.timeStamp = nTimeStamp;
        ByteBuffer pBodyBuffer = BuildMessageBody(bodyBytes, this.type, nTimeStamp);

        Debugger.Assert(pBodyBuffer.position == pBodyBuffer.size);

        /// Encrypt body
        byte[] encryptedBytes = pEncryptor.TransformFinalBlock(pBodyBuffer.GetInternalBuffer(), 0, pBodyBuffer.size);

        ByteBuffer pFinalBuffer = new ByteBuffer(buffer);

        length = (ushort)(HEAD_LENGTH + encryptedBytes.Length);
        Debugger.Assert(HEAD_LENGTH + encryptedBytes.Length <= ConnectionOld.SEND_BUFFER_SIZE);

        pFinalBuffer.WriteUShort(length);
        pFinalBuffer.WriteBytes(encryptedBytes);

        return(length);
    }
        private void InitYotogiSkillTab()
        {
            Debugger.Assert(
                () =>
            {
                Translation.AddTranslatableControl(tabPage_skills);

                rowToSkillID = new Dictionary <int, int>();
                skillIDToRow = new Dictionary <int, int>();
                foreach (DataGridViewColumn column in dataGridView_skill_data.Columns)
                {
                    Translation.AddTranslationAction(column.HeaderText, s => column.HeaderText = s);
                }
                foreach (KeyValuePair <int, Yotogi.SkillData> dataDic in Yotogi.skill_data_list.SelectMany(e => e))
                {
                    string key = dataDic.Value.name;
                    int row    = dataGridView_skill_data.Rows.Add(false, key, 0, 0, (uint)0);
                    Translation.AddTranslationAction(key, s => dataGridView_skill_data.Rows[row].Cells[1].Value = s);
                    rowToSkillID.Add(row, dataDic.Key);
                    skillIDToRow.Add(dataDic.Key, row);
                }
                dataGridView_skill_data.CellContentClick += OnSkillCellContentClick;
                dataGridView_skill_data.CellValueChanged += OnSkillCellValueChanged;
                dataGridView_skill_data.Height            = dataGridView_skill_data.ColumnHeadersHeight
                                                            + dataGridView_skill_data.Rows[0].Height
                                                            * dataGridView_skill_data.RowCount;
            },
                "Failed to initalize yotogi skill tab");
        }
예제 #14
0
    public ByteBuffer(byte[] byteBuffer, int nSize, int iCursorPos = 0)
    {
        Debugger.Assert(nSize <= byteBuffer.Length);

        _buffer  = byteBuffer;
        _nSize   = nSize;
        _iCurosr = iCursorPos;
    }
예제 #15
0
    public void WriteString(string data)
    {
        Debugger.Assert(_iCurosr + data.Length <= _nSize);

        byte[] bytes = Encoding.UTF8.GetBytes(data);
        Buffer.BlockCopy(bytes, 0, _buffer, _iCurosr, data.Length);
        _iCurosr += data.Length;
    }
예제 #16
0
    public void AddEventListener(TypeClass type, Action <EventClass> pListener)
    {
        _Handlers pListenerList = _getListenerList(type);

        Debugger.Assert(!pListenerList.Contains(pListener), "Event " + type.ToString() + " be listened by same function more than once!");

        pListenerList.Add(pListener);
    }
예제 #17
0
            private void UpdateTableValue(PlayerChangeType type)
            {
                object value;

                switch (type)
                {
                case PlayerChangeType.Days:
                    value = Player.status.days;
                    break;

                case PlayerChangeType.PhaseDays:
                    value = Player.status.phase_days;
                    break;

                case PlayerChangeType.SalonBeautiful:
                    value = Player.status.salon_beautiful;
                    break;

                case PlayerChangeType.SalonClean:
                    value = Player.status.salon_clean;
                    break;

                case PlayerChangeType.SalonEvaluation:
                    value = Player.status.salon_evaluation;
                    break;

                case PlayerChangeType.Money:
                    value = Player.status.money;
                    break;

                case PlayerChangeType.SalonLoan:
                    value = Player.status.salon_loan;
                    break;

                case PlayerChangeType.ShopUseMoney:
                    value = Player.status.shop_use_money;
                    break;

                case PlayerChangeType.BestSalonGrade:
                    value = Player.status.best_salon_grade;
                    break;

                case PlayerChangeType.SalonGrade:
                    value = Player.status.current_salon_grade;
                    break;

                case PlayerChangeType.InitSalonLoan:
                    value = Player.status.init_salon_loan;
                    break;

                default:
                    value = "ERROR";
                    break;
                }
                Debugger.Assert(
                    () => { gui.PlayerParameters[type].Cells[PARAMS_COLUMN_VALUE].Value = value; },
                    $"Failed to update player parameter {EnumHelper.GetName(type)}!");
            }
예제 #18
0
    public void WriteUShort(ushort data)
    {
        Debugger.Assert(_iCurosr + 2 <= _nSize);

        _buffer[_iCurosr + 1] = (byte)(data >> 0);
        _buffer[_iCurosr + 0] = (byte)(data >> 8);

        _iCurosr += 2;
    }
예제 #19
0
    /// Note: byte is uint8
    public byte ReadByte()
    {
        _iCurosr--;
        byte data = _buffer[_iCurosr];

        Debugger.Assert(_iCurosr >= 0);

        return(data);
    }
예제 #20
0
        override protected short _deserializeHeader(ByteBuffer byteBuffer)
        {
            _headerType = byteBuffer.FReadByte();
            Debugger.Assert(_headerType == HeaderType.RPCReturn);
            _rpcID = byteBuffer.FReadUShort();
            short dataType = byteBuffer.FReadByte();

            return(dataType);
        }
예제 #21
0
            public static ulong GetHashCodeInt64(string input)
            {
                Debugger.Assert(!string.IsNullOrEmpty(input), "GetHashCodeInt64() - empty input passed in");

                var s1 = input.Substring(0, (int)(input.Length * 0.5f));
                var s2 = input.Substring((int)(input.Length * 0.5f));

                return(((ulong)s1.GetHashCode()) << 0x20 | (ulong)s2.GetHashCode());
            }
예제 #22
0
    public string ReadString(int nLength)
    {
        _iCurosr -= nLength;
        string data = Encoding.UTF8.GetString(_buffer, _iCurosr, nLength);

        Debugger.Assert(_iCurosr >= 0);

        return(data);
    }
예제 #23
0
    public byte FReadByte()
    {
        Debugger.Assert((_iCurosr + 1) <= _nSize);

        byte data = _buffer[_iCurosr];

        _iCurosr++;
        return(data);
    }
예제 #24
0
    public void Start()
    {
        Debugger.Assert(_nLoopCount >= 1 || _nLoopCount == -1, "Loop Count must >= 1 or  equal -1");

        if (_bTriggerOnStart)
        {
            if (_fStartDelayTime == 0)
            {
                if (_nLoopCount > 1 || _nLoopCount == -1)
                {
                    _Start();

                    /// Since already trigger at start, so reduce _nCurLoopCount by one.
                    _nCurLoopCount--;

                    TimerMgr._Instance._PlayTickable(this);

                    _bStartDelayEnd = true;
                    _pHandlerFunc(_pUserData);
                }
                else // _nLoopCount == 1
                {
                    Debugger.Assert(_nLoopCount == 1);
                    _nCurLoopCount--;

                    /// Since _Stop() will clean user data, we store it into a temp var first.
                    object tempUserData = _pUserData;
                    var    tempHandler  = _pHandlerFunc;
                    _Stop();

                    _bStartDelayEnd = true;
                    tempHandler(tempUserData);
                }
            }
            else
            {
                _bStartDelayEnd = false;
                _Start();
                TimerMgr._Instance._PlayTickable(this);
            }
        }
        else
        {
            if (_fStartDelayTime == 0)
            {
                _bStartDelayEnd = true;
            }
            else
            {
                _bStartDelayEnd = false;
            }

            _Start();
            TimerMgr._Instance._PlayTickable(this);
        }
    }
예제 #25
0
        public void DecRef()
        {
            Debugger.Assert(_nRefCount > 0);
            _nRefCount--;

            if (_nRefCount == 0)
            {
                _onRelease();
            }
        }
예제 #26
0
    public ushort ReadUShort()
    {
        _iCurosr -= 2;

        ushort data = (ushort)(((_buffer[_iCurosr + 1] & 0xff) | _buffer[_iCurosr + 0] << 8));;

        Debugger.Assert(_iCurosr >= 0);

        return(data);
    }
예제 #27
0
    public ushort FReadUShort()
    {
        Debugger.Assert((_iCurosr + 2) <= _nSize);

        ushort data = (ushort)(((_buffer[_iCurosr + 1] & 0xff) | _buffer[_iCurosr + 0] << 8));;

        _iCurosr += 2;

        return(data);
    }
예제 #28
0
    public bool IsConnected()
    {
#if UNITY_EDITOR
        if (_connectionState == ConnectionState.CONNECTED || _connectionState == ConnectionState.VALIDATED)
        {
            Debugger.Assert(_tcpClient != null && _tcpClient.Connected);
        }
#endif
        return(_connectionState == ConnectionState.CONNECTED || _connectionState == ConnectionState.VALIDATED);
    }
예제 #29
0
    public string FReadString(int nLength)
    {
        Debugger.Assert((_iCurosr + nLength) <= _nSize);

        string data = Encoding.UTF8.GetString(_buffer, _iCurosr, nLength);

        _iCurosr += nLength;

        return(data);
    }
예제 #30
0
    /// Will Stop the tickable first and then free back it to pool.
    virtual public void StopAndKill()
    {
        Debugger.Assert(_isType(TickableType.Pooled));
        Debugger.Assert(!_AutoKill);

        Stop();

        _AutoKill = true;
        DecRef();
    }