Example #1
0
 protected override void OnClicked(GameObject _go)
 {
     if (_go.name.Equals("BtnReg"))
     {
         if (mAccInput.text.Length == 0 || mPassInput.text.Length == 0 || mPassInput0.text.Length == 0)
         {
             PopWindowManager.AddMsg("输入信息不能为空");
         }
         else if (mAccInput.text.Length < 2 || mPassInput.text.Length < 4)
         {
             PopWindowManager.AddMsg("注册信息不合法");
         }
         else if (!mPassInput.text.Equals(mPassInput0.text))
         {
             PopWindowManager.AddMsg("密码不匹配");
         }
         GameProtocol.dto.AccountModel model = new GameProtocol.dto.AccountModel();
         model.account  = mAccInput.text;
         model.password = mPassInput.text;
         loginhandler.register(model);
         PopWindowManager.AddMsg("正在向服务器请求注册...");
     }
     else if (_go.name.Equals("BtnCancelReg"))
     {
         //base.Hide();
         base.SetNewState(State.login);
     }
 }
Example #2
0
    //写消息
    public void write(byte type, int area, int command, object message)
    {
        ByteArray arr = new ByteArray();

        arr.write(type);
        arr.write(area);
        arr.write(command);
        if (message != null)
        {
            arr.write(SerializeUtil.encode(message));
        }
        byte[]    result  = arr.getBuff();
        ByteArray sendArr = new ByteArray();

        sendArr.write(arr.Length);
        sendArr.write(result);
        try
        {
            socket.Send(sendArr.getBuff());
        }catch (Exception e)
        {
            Debug.Log("网络错误,请从新连接" + e.Message);
            PopWindowManager.AddMsg("网络连接失败");
        }
        sendArr.Close();
        arr.Close();
        //return result;
    }
Example #3
0
 protected override void OnClicked(GameObject _go)
 {
     if (_go.name.Equals("btnlogin"))
     {
         if (accInput.text.Length == 0 || passInput.text.Length == 0)
         {
             PopWindowManager.AddMsg("账号密码不能为空");
             return;
         }
         else if (accInput.text.Length < 2)
         {
             PopWindowManager.AddMsg("账号至少为2个字符");
             return;
         }
         else if (passInput.text.Length < 4)
         {
             PopWindowManager.AddMsg("密码至少为4个字符");
             return;
         }
         GameProtocol.dto.AccountModel model = new GameProtocol.dto.AccountModel();
         model.account  = accInput.text;
         model.password = passInput.text;
         //登陆的时候像服务器发送消息
         loginhandler.login(model);
         if (toggle.isOn)
         {
             //保存账号密码
         }
         PopWindowManager.AddMsg("正在向服务器请求登陆...");
     }
 }
Example #4
0
    void reg(int value)
    {
        switch (value)
        {
        case 0:
            //注册成功
            if (OnReg != null)
            {
                OnReg(value);
            }
            break;

        case 1:
            //账号存在
            PopWindowManager.AddMsg("账号存在");
            break;

        case 2:
            //账号不合法
            PopWindowManager.AddMsg("账号不合法");
            break;

        case 3:
            //密码不合法
            PopWindowManager.AddMsg("密码不合法");
            break;
        }
    }
Example #5
0
    void login(int value)
    {
        switch (value)
        {
        case 0:
            //登陆成功
            if (OnLogin != null)
            {
                OnLogin(value);
            }
            break;

        case 1:
            //账号不存在
            PopWindowManager.AddMsg("账号不存在");
            break;

        case 2:
            //密码错误
            PopWindowManager.AddMsg("密码错误,从新输入");
            break;

        case 3:

            //账号已经登陆
            break;
        }
    }
Example #6
0
 void OnLoadSelectScene()
 {
     timeDialogUI.OnHide();
     PopWindowManager.AddMsg("匹配成功,进入选择界面");
     //Application.LoadLevel(2);
     Application.LoadLevelAsync(2);
 }
Example #7
0
 void create(bool message)
 {
     if (message)
     {
         OnCreate();//创建成功
     }
     else
     {
         PopWindowManager.AddMsg("创建角色失败");
     }
 }
Example #8
0
 void online(UserModel user)
 {
     if (user == null)
     {
         PopWindowManager.AddMsg("上线失败");
     }
     else
     {
         //PopWindowManager.AddMsg("用户上线成功");
         Online(user);//用户上线成功后
     }
 }
Example #9
0
 void Awake()
 {
     nameInput   = transform.Find("createbg/InputField").GetComponent <InputField>();
     userhandler = GameObject.Find("NetWork").AddComponent <UserHandler>();
     transform.Find("createbg/btncreate").GetComponent <Button>().onClick.AddListener(delegate() {
         if (nameInput.text == null || nameInput.text.Length < 2)
         {
             PopWindowManager.AddMsg("名称不合法");
             return;
         }
         userhandler.applyCreate(nameInput.text);//通过用户模块向服务器申请创建角色
     });
 }
Example #10
0
 private NetIO()
 {
     try
     {
         IPAddress ipAddr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         //socket.Connect(ipAddr, port);//113.57.178.60/27.17.53.60
         socket.Connect("1462z254b3.iok.la", 16367);
         socket.BeginReceive(readBuffer, 0, 1024, SocketFlags.None, ReceiveCallBack, readBuffer);
     }
     catch (System.Exception ex)
     {
         string msg = String.Format("无法连接到服务器,{0}", ex.Message);
         PopWindowManager.AddMsg(msg);
     }
 }
Example #11
0
 private void ReceiveCallBack(IAsyncResult ar)
 {
     try
     {
         int    length  = socket.EndReceive(ar);//返回当前socket收到的消息长度
         byte[] message = new byte[length];
         Buffer.BlockCopy(readBuffer, 0, message, 0, length);
         cache.AddRange(message);//将接受到的消息添加至缓冲区
         if (!isReading)
         {
             isReading = true;
             OnData();
         }
     }
     catch (System.Exception ex)
     {
         Debug.Log("远程服务器断开连接.");
         PopWindowManager.AddMsg("远程服务器断开连接..");
         socket.Close();
     }
     socket.BeginReceive(readBuffer, 0, 1024, SocketFlags.None, ReceiveCallBack, readBuffer);
 }
Example #12
0
    //接收服务器消息
    public override void MessageReceive(SocketModel model)
    {
        switch (model.Command)
        {
        case SelectProtocol.DESTORY_BRO:
            Application.LoadLevel(1);
            break;

        case SelectProtocol.ENTER_SRES:
            enter(model.GetMessage <SelectRoomDTO>());
            break;

        case SelectProtocol.ENTER_EXBRO:
            enter(model.GetMessage <int>());
            break;

        case SelectProtocol.SELECT_SRES:
            PopWindowManager.AddMsg("选择英雄失败");
            break;

        case SelectProtocol.SELECT_BRO:
            select(model.GetMessage <SelectModel>());
            break;

        case SelectProtocol.TALK_BRO:
            talk(model.GetMessage <string>());
            break;

        case SelectProtocol.READY_BRO:
            ready(model.GetMessage <SelectModel>());
            break;

        case SelectProtocol.FIGHT_BRO:
            Application.LoadLevel(3);
            break;
        }
    }