コード例 #1
0
ファイル: SV_MAIN.cs プロジェクト: optimus-code/Q2Sharp
        public static void Gotnewcl(Int32 i, Int32 challenge, String userinfo, netadr_t adr, Int32 qport)
        {
            SV_MAIN.sv_client = SV_INIT.svs.clients[i];
            var     edictnum = i + 1;
            edict_t ent      = GameBase.g_edicts[edictnum];

            SV_INIT.svs.clients[i].edict     = ent;
            SV_INIT.svs.clients[i].challenge = challenge;
            if (!(PlayerClient.ClientConnect(ent, userinfo)))
            {
                if (Info.Info_ValueForKey(userinfo, "rejmsg") != null)
                {
                    Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\\n" + Info.Info_ValueForKey(userinfo, "rejmsg") + "\\nConnection refused.\\n");
                }
                else
                {
                    Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\\nConnection refused.\\n");
                }
                Com.DPrintf("Game rejected a connection.\\n");
                return;
            }

            SV_INIT.svs.clients[i].userinfo = userinfo;
            SV_UserinfoChanged(SV_INIT.svs.clients[i]);
            Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "client_connect");
            Netchan.Setup(Defines.NS_SERVER, SV_INIT.svs.clients[i].netchan, adr, qport);
            SV_INIT.svs.clients[i].state = Defines.cs_connected;
            SZ.Init(SV_INIT.svs.clients[i].datagram, SV_INIT.svs.clients[i].datagram_buf, SV_INIT.svs.clients[i].datagram_buf.Length);
            SV_INIT.svs.clients[i].datagram.allowoverflow = true;
            SV_INIT.svs.clients[i].lastmessage            = SV_INIT.svs.realtime;
            SV_INIT.svs.clients[i].lastconnect            = SV_INIT.svs.realtime;
            Com.DPrintf("new client added.\\n");
        }
コード例 #2
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static bool StringToAdr(string s, netadr_t a)
        {
            if (s.EqualsIgnoreCase("localhost") || s.EqualsIgnoreCase("loopback"))
            {
                a.Set(net_local_adr);
                return(true);
            }

            try
            {
                String[] address = s.Split(":");
                a.ip   = IPAddress.Parse(address[0]);
                a.type = Defines.NA_IP;
                if (address.Length == 2)
                {
                    a.port = Lib.Atoi(address[1]);
                }
                return(true);
            }
            catch (Exception e)
            {
                Com.Println(e.Message);
                return(false);
            }
        }
コード例 #3
0
ファイル: SV_MAIN.cs プロジェクト: optimus-code/Q2Sharp
 static SV_MAIN( )
 {
     for (var i = 0; i < Defines.MAX_MASTERS; i++)
     {
         master_adr[i] = new netadr_t();
     }
 }
コード例 #4
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static void SendPacket(int sock, int length, byte[] data, netadr_t to)
        {
            if (to.type == Defines.NA_LOOPBACK)
            {
                SendLoopPacket(sock, length, data, to);
                return;
            }

            if (ip_sockets[sock] == null)
            {
                return;
            }
            if (to.type != Defines.NA_BROADCAST && to.type != Defines.NA_IP)
            {
                Com.Error(Defines.ERR_FATAL, "NET_SendPacket: bad address type");
                return;
            }

            try
            {
                IPEndPoint dstSocket = new IPEndPoint(to.GetInetAddress(), to.port);
                ip_channels[sock].Send(ByteBuffer.Wrap(data, 0, length), dstSocket);
            }
            catch (Exception e)
            {
                Com.Println("NET_SendPacket ERROR: " + e + " to " + AdrToString(to));
            }
        }
コード例 #5
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static void SendLoopPacket(int sock, int length, byte[] data, netadr_t to)
        {
            int        i;
            loopback_t loop;

            loop = loopbacks[sock ^ 1];
            i    = loop.send & (MAX_LOOPBACK - 1);
            loop.send++;
            System.Array.Copy(data, 0, loop.msgs[i].data, 0, length);
            loop.msgs[i].datalen = length;
        }
コード例 #6
0
        /**
         * Initializes player structures after successfull connection.
         */
        public static void gotnewcl(int i, int challenge, string userinfo, netadr_t adr, int qport)
        {
            // build a new connection
            // accept the new client
            // this is the only place a client_t is ever initialized

            SV_MAIN.sv_client = SV_INIT.svs.clients[i];

            var edictnum = i + 1;

            var ent = GameBase.g_edicts[edictnum];

            SV_INIT.svs.clients[i].edict = ent;

            // save challenge for checksumming
            SV_INIT.svs.clients[i].challenge = challenge;

            // get the game a chance to reject this connection or modify the
            // userinfo
            if (!PlayerClient.ClientConnect(ent, userinfo))
            {
                if (Info.Info_ValueForKey(userinfo, "rejmsg") != null)
                {
                    Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\n" + Info.Info_ValueForKey(userinfo, "rejmsg") + "\nConnection refused.\n");
                }
                else
                {
                    Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\nConnection refused.\n");
                }

                Com.DPrintf("Game rejected a connection.\n");

                return;
            }

            // parse some info from the info strings
            SV_INIT.svs.clients[i].userinfo = userinfo;
            SV_MAIN.SV_UserinfoChanged(SV_INIT.svs.clients[i]);

            // send the connect packet to the client
            Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "client_connect");

            Netchan.Setup(Defines.NS_SERVER, SV_INIT.svs.clients[i].netchan, adr, qport);

            SV_INIT.svs.clients[i].state = Defines.cs_connected;

            SZ.Init(SV_INIT.svs.clients[i].datagram, SV_INIT.svs.clients[i].datagram_buf, SV_INIT.svs.clients[i].datagram_buf.Length);

            SV_INIT.svs.clients[i].datagram.allowoverflow = true;
            SV_INIT.svs.clients[i].lastmessage            = SV_INIT.svs.realtime;  // don't timeout
            SV_INIT.svs.clients[i].lastconnect            = SV_INIT.svs.realtime;
            Com.DPrintf("new client added.\n");
        }
コード例 #7
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static bool CompareBaseAdr(netadr_t a, netadr_t b)
        {
            if (a.type != b.type)
            {
                return(false);
            }
            if (a.type == Defines.NA_LOOPBACK)
            {
                return(true);
            }
            if (a.type == Defines.NA_IP)
            {
                return(a.ip == b.ip);
            }

            return(false);
        }
コード例 #8
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static bool GetLoopPacket(int sock, netadr_t net_from, sizebuf_t net_message)
        {
            loopback_t loop = loopbacks[sock];

            if (loop.send - loop.get > MAX_LOOPBACK)
            {
                loop.get = loop.send - MAX_LOOPBACK;
            }
            if (loop.get >= loop.send)
            {
                return(false);
            }
            int i = loop.get & (MAX_LOOPBACK - 1);

            loop.get++;
            System.Array.Copy(loop.msgs[i].data, 0, net_message.data, 0, loop.msgs[i].datalen);
            net_message.cursize = loop.msgs[i].datalen;
            net_from.Set(net_local_adr);
            return(true);
        }
コード例 #9
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
        public static bool GetPacket(int sock, netadr_t net_from, sizebuf_t net_message)
        {
            if (GetLoopPacket(sock, net_from, net_message))
            {
                return(true);
            }

            if (ip_sockets[sock] == null)
            {
                return(false);
            }
            try
            {
                ByteBuffer        receiveBuffer = ByteBuffer.Wrap(net_message.data);
                InetSocketAddress srcSocket     = (InetSocketAddress)ip_channels[sock].Receive(receiveBuffer);
                if (srcSocket == null)
                {
                    return(false);
                }
                net_from.ip   = srcSocket.GetAddress().GetAddress();
                net_from.port = srcSocket.GetPort();
                net_from.type = Defines.NA_IP;
                int packetLength = receiveBuffer.Position;
                if (packetLength > net_message.maxsize)
                {
                    Com.Println("Oversize packet from " + AdrToString(net_from));
                    return(false);
                }

                net_message.cursize            = packetLength;
                net_message.data[packetLength] = 0;
                return(true);
            }
            catch (Exception e)
            {
                Com.DPrintf("NET_GetPacket: " + e + " from " + AdrToString(net_from) + "\\n");
                return(false);
            }
        }
コード例 #10
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
 public static string BaseAdrToString(netadr_t a)
 {
     return(a.ip.ToString());
 }
コード例 #11
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
 public static bool CompareAdr(netadr_t a, netadr_t b)
 {
     return(a.ip == b.ip);
 }
コード例 #12
0
ファイル: NET.cs プロジェクト: optimus-code/Q2Sharp
 public static bool IsLocalAddress(netadr_t adr)
 {
     return(CompareAdr(adr, net_local_adr));
 }