Example #1
0
        public void SendLoginRequest(string username, string password, string productname)
        {
            Console.WriteLine("send request: username: {0}\npassword: {1}\nproductname: {2}\n", username, password, productname);
            UserAccountRequest loginCredentials = (UserAccountRequest)IntrepidSerialize.TakeFromPool(PacketType.UserAccountRequest);

            loginCredentials.password.Copy(password);
            loginCredentials.username.Copy(username);
            loginCredentials.connectionId = 0;
            loginCredentials.product_name.Copy(productname);
            socket.Send(loginCredentials);
        }
Example #2
0
        public void ShouldNotWriteToClosedSocketIfCancelled()
        {
            Exception ex = null;

            _wrapper.Dispose();

            var task = _wrapper.Send(new byte[1], () => {}, e => { ex = e; });

            Assert.IsNull(task);
            Assert.IsNull(ex);
        }
 public void Send(string message, string user)
 {
     using (var socket = new SocketWrapper(Configuration.SERVER, 1012))
     {
         var data = string.Format("SEND MESSAGE {0}:{1}:{2}\r\n", Configuration.UserIdentification, user, message);
         socket.Send(data);
     }
 }
Example #4
0
 void ForwardAllOutgoingPackets()
 {
     lock (containersLock)
     {
         foreach (var packetPair in containers.outgoingPackets)
         {
             if (packetPair.connectionId != InvalidConnectionId)
             {
                 ServerConnectionHeader gatewayHeader = (ServerConnectionHeader)IntrepidSerialize.TakeFromPool(PacketType.ServerConnectionHeader);
                 gatewayHeader.connectionId = packetPair.connectionId;
                 gatewaySocket.Send(gatewayHeader);
             }
             gatewaySocket.Send(packetPair.packet);
         }
         containers.outgoingPackets.Clear();
     }
 }
Example #5
0
        public void ShouldHandleObjectDisposedOnSend()
        {
            Exception ex = null;

            _wrapper.Dispose();
            _wrapper.Send(new byte[1], () => {}, e => { ex = e; });
            Assert.IsInstanceOf <ObjectDisposedException>(ex);
        }
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                numPacketsReceived++;
                // normal processing
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }
                    else
                    {
                        Console.Write("Entity update packet {0}\n", tempEntityId);
                    }
                    continue;
                }
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                IntrepidSerialize.ReturnToPool(packet);
            }
        }
Example #7
0
        private void ForwardAllOutgoingPackets()
        {
            Queue <BasePacket> packets;

            lock (packetLock)
            {
                packets         = outgoingPackets;
                outgoingPackets = new Queue <BasePacket>();
            }
            foreach (var packet in packets)
            {
                if (socket != null)
                {
                    socket.Send(packet);
                }
                else
                {
                    CreateFakeResponse(packet);
                }
            }
        }
Example #8
0
 //------------------------------- socket and update ----------------
 public void Send(BasePacket bp)
 {
     socket.Send(bp);
 }
Example #9
0
        void HandleNormalPackets(Queue <BasePacket> listOfPackets)
        {
            foreach (var packet in listOfPackets)
            {
                //Console.WriteLine("normal packet received {0} .. isLoggedIn = true", packet.PacketType);
                numPacketsReceived++;
                // normal processing
                if (packet is PlayerFullPacket && localPlayer.entityId == 0)
                {
                    localPlayer.entityId = (packet as PlayerFullPacket).entityId;
                }

                /*     ServerTick st = packet as ServerTick;
                 *   if(st != null)
                 *   {
                 *       Console.WriteLine("server tick {0}", st.TickCount);
                 *
                 *       continue;
                 *   }*/
                KeepAlive ka = packet as KeepAlive;
                if (ka != null)
                {
                    KeepAliveResponse kar = (KeepAliveResponse)IntrepidSerialize.TakeFromPool(PacketType.KeepAliveResponse);
                    socket.Send(kar);
                }

                if (packet is ServerPingHopperPacket)
                {
                    ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
                    hopper.Stamp("client end");
                    hopper.PrintList();
                }
                if (packet is WorldEntityPacket)
                {
                    WorldEntityPacket wep = packet as WorldEntityPacket;
                    if (localPlayer.entityId == wep.entityId)
                    {
                        localPlayer.position = wep.position.Get();
                        localPlayer.rotation = wep.rotation.Get();
                    }
                }
                EntityPacket ep = packet as EntityPacket;
                if (ep != null)
                {
                    //entityId = ep.entityId;
                    int tempEntityId = ep.entityId;
                    if (localPlayer.entityId == tempEntityId)
                    {
                        Console.Write("This entity packet updated {0}\n", tempEntityId);
                    }

                    /* else
                     * {
                     *   Console.Write("Entity update packet {0}\n", tempEntityId);
                     * }*/
                    continue;
                }

                // Console.WriteLine("normal packet received {0}", packet.PacketType);

                IntrepidSerialize.ReturnToPool(packet);
            }
        }
Example #10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (serversRunning != 0)
            {
                return;
            }

            Interlocked.Increment(ref serversRunning);

            // Server start
            serverTaskMain = new Task(() =>
            {
                // Server setup
                SocketWrapper[] listenSocketArr = new SocketWrapper[1];
                uint q = SocketsWrapper.Socket(AddressFamily.QCC_AF_INET, SocketType.QCC_SOCK_STREAM, listenSocketArr);
                SocketWrapper listenSocket = listenSocketArr[0];

                q = listenSocket.Bind("0.0.0.0", Port);
                q = listenSocket.Listen(10);

                for (int s = 0; s < Servers; s++)
                {
                    if (s != 0)
                    {
                        Interlocked.Increment(ref serversRunning);
                    }
                    _serverTasks[s] = new Task(() =>
                    {
                        string[] remoteAddr          = new string[1];
                        int[] remotePort             = new int[1];
                        SocketWrapper[] newSocketArr = new SocketWrapper[1];

                        while (listenSocket.Accept(remoteAddr, remotePort, newSocketArr) == 0)
                        {
                            int bytesLeft = PatternLength;
                            int byteCount = 0;
                            using (SocketWrapper newSocket = newSocketArr[0])
                            {
                                int[] sentArr = new int[1];
                                while (bytesLeft != 0)
                                {
                                    byte[] tempBytes = new byte[Math.Min(bytesLeft, MaxSendBuffer)];
                                    for (int i = 0; i < tempBytes.Length; i++)
                                    {
                                        tempBytes[i] = (byte)((i + byteCount) % 256);
                                    }
                                    q = newSocket.Send(tempBytes, tempBytes.Length, sentArr);
                                    if (q != 0)
                                    {
                                        break;
                                    }
                                    byteCount += sentArr[0];
                                    bytesLeft -= sentArr[0];
                                }
                            }
                        }

                        Interlocked.Decrement(ref serversRunning);
                    });
                    _serverTasks[s].Start();
                }
            });
            serverTaskMain.Start();
        }
Example #11
0
 //------------------------------- socket and update ----------------
 public void Send(BasePacket bp)
 {
     //if(socket != null)
     socket?.Send(bp);
 }
Example #12
0
 public void ShouldHandleObjectDisposedOnSend()
 {
     _wrapper.Dispose();
     _wrapper.Send(new byte[1], () => {}, Assert.IsInstanceOf <ObjectDisposedException>);
 }