コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="protocoBase"></param>
        public void Register(TCP conn, ProtocolBase protocoBase)
        {
            ProtocolBytes protoco = (ProtocolBytes)protocoBase;

            object[] vs        = protoco.GetDecode();
            string   protoName = vs[0].ToString();
            string   strFromat = "[收到注册协议]" + conn.GetAddress();

            protoco = new ProtocolBytes();
            protoco.SetProtocol(Fursion_Protocol.Register);
            UserData UD       = JsonConvert.DeserializeObject <UserData>(vs[1].ToString());
            string   Openid   = UD.Openid;
            string   NickName = UD.NickNeam;

            Console.WriteLine(strFromat + "   " + Openid + "   " + NickName);
            var reg = DataMgr.instance.Register(Openid, NickName, UD);

            if (reg)                //
            {
                protoco.AddData(0); //
            }
            else
            {
                protoco.AddData(1);
                conn.Send(protoco);
                return;
            }
            conn.Send(protoco);
            Console.WriteLine("**&&**&&**");
        }
コード例 #2
0
    public void SendRPSData(RPSKind rpsKind)
    {
        // 구조체를 byte배열로 변환합니다.
        byte[] data = new byte[1];
        data[0] = (byte)rpsKind;

        // 데이터를 송신합니다.
        network.Send(data, data.Length);
    }
コード例 #3
0
        public void Write(Bytes data)
        {
            if (tcpSession.CurrentState < TcpState.ESTABLISHED)
            {
                state = State.Closed;
                DebugStub.Print("Connection unexpectedly closed\n");
                throw new Exception("Write: CantSend");
            }

            int bytesToWrite = data.Length;
            int written      = tcpSession.Send(data);

            if (written == -1)
            {
                state = State.Closed;
                // A -1 return value indicates the connection has been closed
                // underneath us while we were trying to write.
                throw new Exception("WriteData: CantSend");
            }
            else if (written != bytesToWrite)
            {
                // This is unexpected; the current implementation always
                // blocks and writes as much data as is provided.
                throw new Exception("Unexpected partial write in TcpSession.WriteData");
            }
        }
コード例 #4
0
        private void MyStream_OnInfo(EasyTCP.EasyTCP Sender, ushort Code, object Value)
        {
            string Message;

            switch (Code)
            {
            case 0:
                SendMessage(Sender, (Dic[Sender] = Value.ToString()) + " joined");
                return;

            case 2:
                Message = string.Join(" ", Value as IEnumerable <int>);
                break;

            case 1:
            case 3:
            case 4:
                Message = Value.ToString();
                break;

            case 5:
            case 6:
                Do4All(TCP => TCP.Send(Code, Value), Sender);
                return;

            default: return;
            }

            SendMessage(Sender, string.Format("{0}> {1}", Dic[Sender], Message));
        }
コード例 #5
0
        public void Logout(TCP conn, ProtocolBase protocoBase)
        {
            ProtocolBytes protocoBytes = new ProtocolBytes();

            protocoBytes.SetProtocol(Fursion_Protocol.Logout);
            protocoBytes.AddData(0);
            if (conn.Player == null)
            {
                conn.Send(protocoBytes);
                NMC.instance.CloseTCP(conn);
            }
            else
            {
                conn.Send(protocoBytes);
                conn.Player.Logout();
            }
        }
コード例 #6
0
        public static void FalseCheckOpenid(TCP conn)
        {
            ProtocolBytes RetBytes = new ProtocolBytes();

            RetBytes.SetProtocol(Fursion_Protocol.CheckOpenid);
            RetBytes.AddData(1);
            conn.Send(RetBytes);
        }
コード例 #7
0
        void UCSendFile_Load(object sender, EventArgs e)
        {
            //throw new NotImplementedException();

            Task.Run(() =>
            {
                //tcp.Send(FilePath, FileName, RemoteIp);
                tcp.Send(FilePath, FileName, new IPEndPoint(RemoteIp, Sysconstant.port));
            });
            time = new System.Threading.Timer(new System.Threading.TimerCallback(ShowRate), null, 0, 100);
        }
コード例 #8
0
        public void JSONTEST(TCP conn, ProtocolBase protocoBase)
        {
            Friend friend  = new Friend();
            string jsonstr = JsonConvert.SerializeObject(friend);

            Console.WriteLine("JSON测试    " + jsonstr);
            ProtocolBytes bytes = new ProtocolBytes();

            bytes.AddData("JSONTEST");
            bytes.AddData(jsonstr);
            conn.Send(bytes);
        }
コード例 #9
0
 public void Reconnect(TCP conn, ProtocolBase proto)
 {
     try
     {
         ProtocolBytes bytes   = (ProtocolBytes)proto;
         object[]      vs      = bytes.GetDecode();
         LoginReceipt  receipt = JsonConvert.DeserializeObject <LoginReceipt>(bytes.GetDecode()[1].ToString());
         for (int i = 0; i < NMC.instance.tcps.Length; i++)
         {
             if (NMC.instance.tcps[i] == null)
             {
                 continue;
             }
             if (NMC.instance.tcps[i].Player == null)
             {
                 continue;
             }
             if (NMC.instance.tcps[i].Player.Openid == receipt.UserOpenid)
             {
                 if (NMC.instance.tcps[i].Player.NowDeviceUID != receipt.DeviceUID)
                 {
                     Console.WriteLine("ReConnection Check failed");
                     NMC.instance.CloseTCP(conn);
                     return;
                 }
                 conn.Player          = NMC.instance.tcps[i].Player;
                 conn.Player.Conn     = conn;
                 NMC.instance.tcps[i] = null;
                 ProtocolBytes Ret = new ProtocolBytes();
                 Ret.SetProtocol(Fursion_Protocol.ReConnectRet);
                 conn.Send(Ret);
                 return;
             }
             else
             {
                 NMC.instance.CloseTCP(conn);
             }
         }
         Console.WriteLine(" This User Not Find ");
         Thread ChechOpenidT = new Thread(new ThreadStart(delegate { DataMgr.instance.CheckOpenid(conn, receipt, true); }))
         {
             Name = receipt.UserOpenid
         };
         ChechOpenidT.Start();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message + " ReConnect");
     }
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: valentinbreiz/Sharpen
        private static unsafe void HttpTest()
        {
            TCPConnection con = TCP.Bind(80);

            string message  = "<!doctype html><html><title>Van Sharpen</title><body>Wij serveren dit van Sharpen naar Dossche</body></html>";
            string httpResp = "HTTP/1.1 200 OK\r\nDate: Fri, 13 May 2005 05:51:12 GMT\r\nServer: Sharpen :)\r\nLast-Modified: Fri, 13 May 2005 05:25:02 GMT\r\nAccept-Ranges: bytes\r\nContent-Length: ";

            string count = message.Length.ToString();

            httpResp = String.Merge(httpResp, count);
            httpResp = String.Merge(httpResp, "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");

            string finalResp = String.Merge(httpResp, message);

            TCPPacketDescriptor *ptr;

            while (true)
            {
                ptr = TCP.Read(con);
                if (ptr == null)
                {
                    continue;
                }

                if (ptr->Type == TCPPacketDescriptorTypes.ACCEPT)
                {
                    Console.Write("New connection from: ");
                    for (int i = 0; i < 3; i++)
                    {
                        Console.WriteNum(ptr->Data[i]);
                        Console.Write('.');
                    }
                    Console.WriteNum(ptr->Data[3]);
                    Console.Write(" with XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RECEIVE)
                {
                    Console.Write("New data from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");

                    TCP.Send(con, ptr->xid, (byte *)Util.ObjectToVoidPtr(finalResp), (uint)finalResp.Length);

                    TCP.Close(con, ptr->xid);
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RESET)
                {
                    Console.Write("RESET from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.CLOSE)
                {
                    Console.Write("CLOSE from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else
                {
                    Console.WriteLine("Invalid ptr->Type!");
                    break;
                }

                Heap.Free(ptr);
            }

            Console.WriteLine("EXIAT");
            for (;;)
            {
                ;
            }

            TCP.Free(con);
        }
コード例 #11
0
 public void send_state()
 {
     TCP.Send(JSON.Serialize(this));
 }
コード例 #12
0
 // Fonctions du block write
 void set_carott(Carott carott)
 {
     // state.carot = carott;
     TCP.Send(new Write_set_carott_Message(carott).Serialize());
 }
コード例 #13
0
 void set_potato_str(int id, string value)
 {
     TCP.Send(new Write_set_potato_str_Message(id, value).Serialize());
 }
コード例 #14
0
        public static void TrueCheckOpenid(TCP conn, LoginReceipt receipt, bool ISReConn)
        {
            ProtocolBytes RetBytes = new ProtocolBytes();

            RetBytes.SetProtocol(Fursion_Protocol.CheckOpenid);
            if (receipt.OnlineRec)
            {
                if (Player.Kickoff(receipt.UserOpenid, false))
                {
                    RetBytes.AddData(2);
                    conn.Send(RetBytes);
                    return;
                }
            }
            else
            {
                if (Player.Kickoff(receipt.UserOpenid, true))
                {
                    RetBytes.AddData(2);
                    conn.Send(RetBytes);
                    return;
                }
            }
            PlayerData playerData = DataMgr.instance.GetPlayerData(receipt.UserOpenid);

            if (playerData == null)
            {
                RetBytes.AddData(-1);
                conn.Send(RetBytes);
                return;
            }
            conn.Player = new Player(receipt.UserOpenid, conn)
            {
                Data = playerData
            };
            conn.Player.NowDeviceUID = receipt.DeviceUID;
            RetBytes.AddData(0);//Success
            conn.Player.UserData = DataMgr.instance.GetUserData(conn.Player.Openid);
            Friend friend = FriendMC.A.InitFriendListInfo(conn.Player);

            if (friend.GoodList.Keys.Count != 0)
            {
                ProtocolBytes onlineRet = new ProtocolBytes();
                onlineRet.SetProtocol(Fursion_Protocol.Friend_OnlineNotice);
                onlineRet.AddData(conn.Player.Openid);
                foreach (string id in friend.GoodList.Keys)
                {
                    if (FriendMC.OnlinePlayerList.ContainsKey(id))
                    {
                        FriendMC.OnlinePlayerList[id].Send(onlineRet);
                    }
                }
            }
            string FriendListStr = JsonConvert.SerializeObject(friend);

            RetBytes.AddData(FriendListStr);
            ServerMC.This.GetServerInfo(RetBytes, conn);
            if (ISReConn)
            {
                ProtocolBytes Ret = new ProtocolBytes();
                Ret.SetProtocol(Fursion_Protocol.ReConnectRet);
                conn.Send(Ret);
            }
            Console.WriteLine("登录成功******发送   ");
        }