Exemplo n.º 1
0
    public void OnClick()
    {
        if (count == 0)
        {
            //NetSystem.Instance.Connect((int)RosettaSetup.NetCtr.Lobby, "ws://127.0.0.1:8080/PearlHarbor/Game", 8080);
            NetSystem.Instance.Connect((int)NetCtr.Lobby, "192.168.1.111", 33333);
        }
        if (count > 0)
        {
            NetPacket pa = new NetPacket(PacketType.CS_HelloWorld);
            XMessage.CS_HelloWorld proto = new XMessage.CS_HelloWorld();
            proto.Int = count + 70000;
            proto.Float = 0.998f;
            proto.String = "helloworld";
            proto.Long = 22222 - count;
            pa.Proto = proto;
            NetSystem.Instance.Send((int)NetCtr.Lobby, pa);
        }

        Alkaid.MyRandom mr = new Alkaid.MyRandom();
        Debug.LogWarning("Framework 1000   " + mr.GetRandomNum1000());

        GameObject go = mr.CreateOne();
        //go.transform.parent = this.transform;
        go.name = "createone:" + count++;
        go.transform.localPosition = Vector3.one * count;

        //WindowManager.Instance.ShowWindow("LogoWindow");
    }
Exemplo n.º 2
0
    // 向Network Manager的队列传递数据
    void PushPacket2(NetBitStream stream)
    {
        NetPacket packet = new NetPacket();
        stream.BYTES.CopyTo(packet._bytes, 0);
        packet._peer = stream._socket;

        _netMgr.AddPacket(packet);
    }
Exemplo n.º 3
0
    // 向Network Manager的队列传递内部消息
    void PushPacket(ushort msgid, string exception)
    {
        NetPacket packet = new NetPacket();
        packet.SetIDOnly(msgid);
        packet._error = exception;
        packet._peer = _socket;

        _netMgr.AddPacket(packet);
    }
Exemplo n.º 4
0
    // 开始读取版本2 忽略消息ID
    public void BeginRead2(NetPacket packet)
    {
        packet._bytes.CopyTo(this.BYTES, 0);

        this._socket = packet._peer;

        _bodyLenght = 0;

        _bodyLenght += SHORT16_LEN;
    }
Exemplo n.º 5
0
    // 开始读取
    public void BeginRead(NetPacket packet, out ushort msgid)
    {
        packet._bytes.CopyTo(this.BYTES, 0);

        this._socket = packet._peer;

        _bodyLenght = 0;

        this.ReadUShort(out msgid);
    }
Exemplo n.º 6
0
 // 数据包入队
 public void AddPacket(NetPacket packet)
 {
     Packets.Enqueue(packet);
 }
Exemplo n.º 7
0
 internal NetDataReader(NetPacket packet)
 {
     SetSource(packet);
 }
Exemplo n.º 8
0
 //if lost, remove from list
 public override void OnLost(NetPacket packet)
 {
     Console.WriteLine("connection lost");
     peerList.Remove(packet.socket);
 }
Exemplo n.º 9
0
 //connection successful, add to peer list
 public override void OnAccepted(NetPacket packet)
 {
     Console.WriteLine("accepting new connection");
     peerList.Add(packet.socket);
 }
Exemplo n.º 10
0
        public override WPDResponse Handle()
        {
            var loginCtx = ContextBase.GetInstance <LoginContext>();

            var account = default(Account);

            using (var ctx = DatabaseService.GetContext())
            {
                account = ctx.Accounts
                          .FirstOrDefault(a => a.UserId == UserId && a.UserSecret == UserSecret);
            }

            if (account == null)
            {
                return new LoginResponse {
                           Result = 1
                }
            }
            ;

            var accessToken = new JObject();

            accessToken["userId"]       = account.UserId;
            accessToken["accessSecret"] = Utils.RandomString(20);
            accessToken["checkCode"]    = Utils.RandomString(32);
            accessToken["platform"]     = "android";

            var user = new User
            {
                UserType              = 1,
                UserId                = account.UserId,
                UserSecret            = account.UserSecret,
                UserAccessToken       = accessToken.ToString(),
                LastVirtualGameServer = 0
            };

            var previousSession = loginCtx.Sessions.FirstOrDefault(s => s.User.UserId == user.UserId && s.User.UserSecret == user.UserSecret);

            if (previousSession != null)
            {
                loginCtx.Sessions.Remove(previousSession);
            }

            loginCtx.Sessions.Add(new LoginSession
            {
                User = user
            });

            // Register user to game servers
            using (var packet = new NetPacket())
            {
                packet.Write((short)OpCode.REGISTER_USER);
                packet.Write(user.UserId);
                packet.Write(user.UserAccessToken);
                loginCtx.GetService <ISCServer>().SendTo(loginCtx.GameServers.Select(d => d.Key), packet);
            }

            return(new LoginResponse
            {
                UserType = user.UserType,
                AccessToken = user.UserAccessToken,
                LastVirtualGameServerId = user.LastVirtualGameServer
            });
        }
Exemplo n.º 11
0
        //sends the packet and deletes it when done (if successful).rv :true success
        public override bool Send(NetPacket pkt)
        {
            lock (sendSentry)
            {
                Log_Verb("Sending NetPacket");
                bool result = false;

                EthernetFrame ef = new EthernetFrame(pkt);

                switch (ef.Protocol)
                {
                case (int)EtherFrameType.NULL:
                    //Adapter Reset

                    //lock (sentry)
                    //{
                    Log_Verb("Reset " + connections.Count + " Connections");
                    ConnectionKey[] keys = connections.Keys.ToArray();
                    foreach (ConnectionKey key in keys)
                    {
                        if (!connections.TryGetValue(key, out Session session))
                        {
                            continue;
                        }
                        session.Reset();
                    }
                    //}
                    break;

                case (int)EtherFrameType.IPv4:
                    result = SendIP((IPPacket)ef.Payload);
                    break;

                    #region "ARP"
                case (int)EtherFrameType.ARP:
                    Log_Verb("ARP");
                    ARPPacket arpPkt = ((ARPPacket)ef.Payload);

                    if (arpPkt.Protocol == (UInt16)EtherFrameType.IPv4)
                    {
                        if (arpPkt.OP == 1)     //ARP request
                        {
                            byte[] gateway;
                            //lock (sentry)
                            //{
                            gateway = dhcpServer.Gateway;
                            //}
                            //if (Utils.memcmp(arpPkt.TargetProtocolAddress, 0, gateway, 0, 4))
                            if (!Utils.memcmp(arpPkt.TargetProtocolAddress, 0, dhcpServer.PS2IP, 0, 4))
                            //it's trying to resolve the virtual gateway's mac addr
                            {
                                ARPPacket arpRet = new ARPPacket();
                                arpRet.TargetHardwareAddress = arpPkt.SenderHardwareAddress;
                                arpRet.SenderHardwareAddress = virturalDHCPMAC;
                                arpRet.TargetProtocolAddress = arpPkt.SenderProtocolAddress;
                                arpRet.SenderProtocolAddress = arpPkt.TargetProtocolAddress;
                                arpRet.OP       = 2;
                                arpRet.Protocol = arpPkt.Protocol;

                                EthernetFrame retARP = new EthernetFrame(arpRet);
                                retARP.DestinationMAC = ps2MAC;
                                retARP.SourceMAC      = virturalDHCPMAC;
                                retARP.Protocol       = (UInt16)EtherFrameType.ARP;
                                vRecBuffer.Enqueue(retARP.CreatePacket());
                                break;
                            }
                        }
                    }

                    result = true;
                    break;

                    #endregion
                case 0x0081:
                    Log_Error("VLAN-tagged frame (IEEE 802.1Q)");
                    throw new NotImplementedException();

                //break;
                default:
                    Log_Error("Unkown EtherframeType " + ef.Protocol.ToString("X4"));
                    break;
                }

                return(result);
            }
        }