Exemplo n.º 1
0
 // the message proc
 public override void proc(tcp.response rsp)
 {
     switch (rsp.cmd)
     {
     case (short)server.cmd.RSP_QUICKPLAY:     // match ok, print the opponent's name
     {
         int    res      = rsp.nextInt();
         string opponent = rsp.nextString();
         Console.WriteLine("cmd=[{0}], sn=[{1}], result=[{2}], opponent=[{3}]", rsp.cmd, rsp.sn, res, opponent);
     }
     break;
     }
 }
Exemplo n.º 2
0
            public result logout(int timeout)
            {
                if (!tc.isConnected())
                    return new result();

                tcp.request req = new tcp.request((short)cmd.REQ_LOGOUT);
                tcp.response rsp = send(req, timeout);
                if (rsp == null)
                    return new result();

                int res = rsp.nextInt();
                string msg = rsp.nextString();
                Console.WriteLine("cmd=[{0}], sn=[{1}], result=[{2}], errmsg=[{3}]", rsp.cmd, rsp.sn, res, msg);
                return new result(res==0, msg);
            }
Exemplo n.º 3
0
            public result login(string usr, string passwd, int timeout /* ms */)
            {
                if (!tc.isConnected())
                {
                    start();
                    if (!tc.isConnected()) return new result(false, "connection lost");
                }

                tcp.request req = new tcp.request((short)cmd.REQ_LOGIN);
                req.encode(usr);
                req.encode(passwd);
                
                tcp.response rsp = send(req, timeout);
                if (rsp == null)
                {
                    return new result(false, "no response");
                }

                int result = rsp.nextInt();
                string errmsg = rsp.nextString();
                Console.WriteLine("cmd=[{0}], sn=[{1}], result=[{2}], errmsg=[{3}]", rsp.cmd, rsp.sn, result, errmsg);
                return new result(result==0, errmsg);
            }