Esempio n. 1
0
        /// <summary>
        /// 处理服务器到客户端的调用
        /// </summary>
        /// <param name="buf"></param>
        private void OnCallScript(KProtoBuf buf)
        {
            S2C_CALL_SCRIPT respond = buf as S2C_CALL_SCRIPT;

            ArrayList remoteObjects = UnpackAll(new MemoryStream(respond.data));

            uint       methodHash = (uint)remoteObjects[0];
            MethodInfo methodInfo = hash2MethodInfo.ContainsKey(methodHash) ? hash2MethodInfo[methodHash] : null;

            if (methodInfo == null)
            {
                //Debugger.LogErrorFormat("Remote call method error, no such function, protocolID = {0}, hashCode = {1}", respond.protocolID, methodHash);
                return;
            }

            //Debug.LogWarning(methodInfo.Name);

            if (Application.isEditor)
            {
                try
                {
                    methodInfo.Invoke(this, FixRemoteCallParams(remoteObjects, methodInfo.GetParameters()));
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("Remote call method error in function hashCode = " + methodHash + " Methodinfo Name: " + methodInfo.Name);
                    Debug.LogException(ex);
                }
            }
            else
            {
                methodInfo.Invoke(this, FixRemoteCallParams(remoteObjects, methodInfo.GetParameters()));
            }

            //回收临时数据
            RemoteBool.ResetPosition();
            RemoteInt8.ResetPosition();
            RemoteInt16.ResetPosition();
            RemoteInt32.ResetPosition();
            RemoteUInt8.ResetPosition();
            RemoteUInt16.ResetPosition();
            RemoteUInt32.ResetPosition();
            RemoteFloat.ResetPosition();
            RemoteDouble.ResetPosition();
            RemoteString.ResetPosition();
            RemoteString.ResetPosition();
            RemoteUInt64.ResetPosition();
        }
Esempio n. 2
0
        private ushort UnPackTable(MemoryStream stream, BinaryReader read, ArrayList retArray, ushort tabSize = 0)
        {
            if (tabSize == 0)
            {
                tabSize = read.ReadUInt16();
            }

            uint        tabEnd = (uint)(stream.Position) + tabSize;
            RemoteTable luaTab = new RemoteTable();

            while (stream.Position < tabEnd)
            {
                ArrayList tabKV = new ArrayList();

                KSDType keyType   = UnPackUp(stream, read, tabKV);
                KSDType valueType = UnPackUp(stream, read, tabKV);

                if (IsNumberType(keyType))
                {
                    int nIndex = Convert.ToInt32(tabKV[0]);
                    switch (valueType)
                    {
                    case KSDType.kstBool:
                        luaTab[nIndex] = RemoteBool.GetItem((bool)tabKV[1]);
                        break;

                    case KSDType.kstInt8:
                        luaTab[nIndex] = RemoteInt8.GetItem((sbyte)tabKV[1]);
                        break;

                    case KSDType.kstInt16:
                        luaTab[nIndex] = RemoteInt16.GetItem((short)tabKV[1]);
                        break;

                    case KSDType.kstInt32:
                        luaTab[nIndex] = RemoteInt32.GetItem((int)tabKV[1]);
                        break;

                    case KSDType.kstUInt8:
                        luaTab[nIndex] = RemoteUInt8.GetItem((byte)tabKV[1]);
                        break;

                    case KSDType.kstUInt16:
                        luaTab[nIndex] = RemoteUInt16.GetItem((ushort)tabKV[1]);
                        break;

                    case KSDType.kstUInt32:
                        luaTab[nIndex] = RemoteUInt32.GetItem((uint)tabKV[1]);
                        break;

                    case KSDType.kstFloat:
                        luaTab[nIndex] = RemoteFloat.GetItem((float)tabKV[1]);
                        break;

                    case KSDType.kstDouble:
                        luaTab[nIndex] = RemoteDouble.GetItem((double)tabKV[1]);
                        break;

                    case KSDType.kstString:
                        luaTab[nIndex] = RemoteString.GetItem((string)tabKV[1]);
                        break;

                    case KSDType.kstBigString:
                        luaTab[nIndex] = RemoteString.GetItem((string)tabKV[1]);
                        break;

                    case KSDType.kstUInt64:
                        luaTab[nIndex] = RemoteUInt64.GetItem((ulong)tabKV[1]);
                        break;

                    case KSDType.kstDataStream:
                        luaTab[nIndex] = tabKV[1] as RemoteTable;
                        break;

                    case KSDType.kstNull:
                        luaTab[nIndex] = null;
                        break;

                    default:
                        Debug.LogError("UnKnow ValueType");
                        break;
                    }
                }
                else if (keyType == KSDType.kstString)
                {
                    string name = tabKV[0] as string;
                    switch (valueType)
                    {
                    case KSDType.kstBool:
                        luaTab[name] = RemoteBool.GetItem((bool)tabKV[1]);
                        break;

                    case KSDType.kstInt8:
                        luaTab[name] = RemoteInt8.GetItem((sbyte)tabKV[1]);
                        break;

                    case KSDType.kstInt16:
                        luaTab[name] = RemoteInt16.GetItem((short)tabKV[1]);
                        break;

                    case KSDType.kstInt32:
                        luaTab[name] = RemoteInt32.GetItem((int)tabKV[1]);
                        break;

                    case KSDType.kstUInt8:
                        luaTab[name] = RemoteUInt8.GetItem((byte)tabKV[1]);
                        break;

                    case KSDType.kstUInt16:
                        luaTab[name] = RemoteUInt16.GetItem((ushort)tabKV[1]);
                        break;

                    case KSDType.kstUInt32:
                        luaTab[name] = RemoteUInt32.GetItem((uint)tabKV[1]);
                        break;

                    case KSDType.kstFloat:
                        luaTab[name] = RemoteFloat.GetItem((float)tabKV[1]);
                        break;

                    case KSDType.kstDouble:
                        luaTab[name] = RemoteDouble.GetItem((double)tabKV[1]);
                        break;

                    case KSDType.kstString:
                        luaTab[name] = RemoteString.GetItem((string)tabKV[1]);
                        break;

                    case KSDType.kstBigString:
                        luaTab[name] = RemoteString.GetItem((string)tabKV[1]);
                        break;

                    case KSDType.kstUInt64:
                        luaTab[name] = RemoteUInt64.GetItem((ulong)tabKV[1]);
                        break;

                    case KSDType.kstDataStream:
                        luaTab[name] = tabKV[1] as RemoteTable;
                        break;

                    case KSDType.kstNull:
                        luaTab[name] = null;
                        break;

                    default:
                        Debug.LogError("UnKnow ValueType");
                        break;
                    }
                }
                else
                {
                    Debug.LogError("RemoteCall UnPackTable error, key type error");
                    throw new NotImplementedException();
                }
            }
            retArray.Add(luaTab);
            return(tabSize);
        }