示例#1
0
        /// <summary>
        /// Connect to server
        /// </summary>
        /// <param name="www"></param>
        /// <param name="port"></param>
        public void ConnectWWW(string www, int port)
        {
            var hostEntry = Dns.GetHostEntry(www);

            if (hostEntry.AddressList != null && hostEntry.AddressList.Length > 0)
            {
                IPEndPoint ipe = new IPEndPoint(hostEntry.AddressList[0], port);
                Connect(ipe);
            }
            else
            {
                AssertThat.Fail("Check host");
            }
        }
示例#2
0
 /// <summary>
 /// 初始化
 /// </summary>
 void Awake()
 {
     if (isLuaEvnExist)
     {
         AssertThat.Fail("Make sure there is only one LuaManager in project");
     }
     else
     {
         isLuaEvnExist = true;
         DontDestroyOnLoad(gameObject);
         Instance = this;
         LuaEnv   = new LuaEnv();
         InitLoader();
     }
 }
示例#3
0
 /// <summary>
 /// Connect to server
 /// </summary>
 public void Connect(IPEndPoint iep)
 {
     lock (_locker)
     {
         AssertThat.IsFalse(IsConnected, "Already Connected");
         AssertThat.IsNotNull(iep, "iep is null");
         ConnectingEvent();
         try
         {
             Socket = new System.Net.Sockets.Socket(iep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         }
         catch (Exception e)
         {
             throw new Exception(e.ToString());
         }
         try
         {
             Socket.BeginConnect(iep, delegate(IAsyncResult ar)
             {
                 try
                 {
                     var socket = ar.AsyncState as System.Net.Sockets.Socket;
                     AssertThat.IsNotNull(socket, "Socket is null when end connect");
                     socket.EndConnect(ar);
                     if (IsConnected)
                     {
                         ConnectedEvent();
                         Receive();
                     }
                     else
                     {
                         AssertThat.Fail("Connect faild");
                     }
                 }
                 catch (Exception e)
                 {
                     throw new Exception(e.ToString());
                 }
             }, Socket);
         }
         catch (Exception e)
         {
             throw new Exception(e.ToString());
         }
     }
 }
示例#4
0
        object GetVariableValue(string type, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                if (type == Common.double_)
                {
                    return((double)0);
                }
                if (type == Common.float_)
                {
                    return((float)0);
                }
                if (type == Common.int32_)
                {
                    return((int)0);
                }
                if (type == Common.int64_)
                {
                    return((long)0);
                }
                if (type == Common.uint32_)
                {
                    return((uint)0);
                }
                if (type == Common.uint64_)
                {
                    return((ulong)0);
                }
                if (type == Common.sint32_)
                {
                    return((int)0);
                }
                if (type == Common.sint64_)
                {
                    return((long)0);
                }
                if (type == Common.fixed32_)
                {
                    return((uint)0);
                }
                if (type == Common.fixed64_)
                {
                    return((ulong)0);
                }
                if (type == Common.sfixed32_)
                {
                    return((int)0);
                }
                if (type == Common.sfixed64_)
                {
                    return((long)0);
                }
                if (type == Common.bool_)
                {
                    return(false);
                }
                if (type == Common.string_)
                {
                    return("");
                }
                if (type == Common.bytes_)
                {
                    return(ByteString.Empty);
                }
                if (type == Common.double_s)
                {
                    return(new RepeatedField <double>());
                }
                if (type == Common.float_s)
                {
                    return(new RepeatedField <float>());
                }
                if (type == Common.int32_s)
                {
                    return(new RepeatedField <int>());
                }
                if (type == Common.int64_s)
                {
                    return(new RepeatedField <long>());
                }
                if (type == Common.uint32_s)
                {
                    return(new RepeatedField <uint>());
                }
                if (type == Common.uint64_s)
                {
                    return(new RepeatedField <ulong>());
                }
                if (type == Common.sint32_s)
                {
                    return(new RepeatedField <int>());
                }
                if (type == Common.sint64_s)
                {
                    return(new RepeatedField <long>());
                }
                if (type == Common.fixed32_s)
                {
                    return(new RepeatedField <uint>());
                }
                if (type == Common.fixed64_s)
                {
                    return(new RepeatedField <ulong>());
                }
                if (type == Common.sfixed32_s)
                {
                    return(new RepeatedField <int>());
                }
                if (type == Common.sfixed64_s)
                {
                    return(new RepeatedField <long>());
                }
                if (type == Common.bool_s)
                {
                    return(new RepeatedField <bool>());
                }
                if (type == Common.string_s)
                {
                    return(new RepeatedField <string>());
                }
                AssertThat.Fail("Type error");
                return(null);
            }

            if (type == Common.float_)
            {
                return(float.Parse(value));
            }
            if (type == Common.int32_)
            {
                return(int.Parse(value));
            }
            if (type == Common.int64_)
            {
                return(long.Parse(value));
            }
            if (type == Common.uint32_)
            {
                return(uint.Parse(value));
            }
            if (type == Common.uint64_)
            {
                return(ulong.Parse(value));
            }
            if (type == Common.sint32_)
            {
                return(int.Parse(value));
            }
            if (type == Common.sint64_)
            {
                return(long.Parse(value));
            }
            if (type == Common.fixed32_)
            {
                return(uint.Parse(value));
            }
            if (type == Common.fixed64_)
            {
                return(ulong.Parse(value));
            }
            if (type == Common.sfixed32_)
            {
                return(int.Parse(value));
            }
            if (type == Common.sfixed64_)
            {
                return(long.Parse(value));
            }
            if (type == Common.bool_)
            {
                return(value == "1");
            }
            if (type == Common.string_)
            {
                return(value.ToString());
            }
            if (type == Common.bytes_)
            {
                return(ByteString.CopyFromUtf8(value.ToString()));
            }
            if (type == Common.double_s)
            {
                string   data  = value.Trim('"');
                string[] datas = data.Split('|');
                RepeatedField <double> newValue = new RepeatedField <double>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(double.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.float_s)
            {
                string   data  = value.Trim('"');
                string[] datas = data.Split('|');
                RepeatedField <float> newValue = new RepeatedField <float>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(float.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.int32_s)
            {
                string              data     = value.Trim('"');
                string[]            datas    = data.Split('|');
                RepeatedField <int> newValue = new RepeatedField <int>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(int.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.int64_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <long> newValue = new RepeatedField <long>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(long.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.uint32_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <uint> newValue = new RepeatedField <uint>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(uint.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.uint64_s)
            {
                string   data  = value.Trim('"');
                string[] datas = data.Split('|');
                RepeatedField <ulong> newValue = new RepeatedField <ulong>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(ulong.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.sint32_s)
            {
                string              data     = value.Trim('"');
                string[]            datas    = data.Split('|');
                RepeatedField <int> newValue = new RepeatedField <int>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(int.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.sint64_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <long> newValue = new RepeatedField <long>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(long.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.fixed32_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <uint> newValue = new RepeatedField <uint>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(uint.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.fixed64_s)
            {
                string   data  = value.Trim('"');
                string[] datas = data.Split('|');
                RepeatedField <ulong> newValue = new RepeatedField <ulong>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(ulong.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.sfixed32_s)
            {
                string              data     = value.Trim('"');
                string[]            datas    = data.Split('|');
                RepeatedField <int> newValue = new RepeatedField <int>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(int.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.sfixed64_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <long> newValue = new RepeatedField <long>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(long.Parse(datas[i]));
                }

                return(newValue);
            }

            if (type == Common.bool_s)
            {
                string               data     = value.Trim('"');
                string[]             datas    = data.Split('|');
                RepeatedField <bool> newValue = new RepeatedField <bool>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(datas[i] == "1");
                }

                return(newValue);
            }

            if (type == Common.string_s)
            {
                string   data  = value.Trim('"');
                string[] datas = data.Split('|');
                RepeatedField <string> newValue = new RepeatedField <string>();
                for (int i = 0; i < datas.Length; i++)
                {
                    newValue.Add(datas[i]);
                }

                return(newValue);
            }

            AssertThat.Fail("Type error");
            return(null);
        }