Example #1
0
        public Player( World world, Session.Client client )
        {
            World = world;
            Shroud = new ShroudRenderer(this, world.Map);

            PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this);

            if (client != null)
            {
                Index = client.Index;
                Palette = PlayerColors[client.PaletteIndex % PlayerColors.Count()].a;
                Color = PlayerColors[client.PaletteIndex % PlayerColors.Count()].c;
                PlayerName = client.Name;
                InternalName = "Multi{0}".F(client.Index);
            }
            else
            {
                Index = -1;
                PlayerName = InternalName = "Neutral";
                Palette = "neutral";
                Color = Color.Gray;	// HACK HACK
            }

            Country = world.GetCountries()
                .FirstOrDefault(c => client != null && client.Country == c.Name)
                ?? world.GetCountries().Random(world.SharedRandom);
        }
Example #2
0
        public static void ServerMain(bool internetServer, string masterServerUrl, string name, int port, int extport, string[] mods)
        {
            Server.masterServerUrl = masterServerUrl;
            isInternetServer = internetServer;
            listener = new TcpListener(IPAddress.Any, port);
            initialMods = mods;
            Name = name;
            ExternalPort = extport;
            randomSeed = (int)DateTime.Now.ToBinary();

            lobbyInfo = new Session();
            lobbyInfo.GlobalSettings.Mods = mods;
            lobbyInfo.GlobalSettings.RandomSeed = randomSeed;

            Console.WriteLine("Initial mods: ");
            foreach( var m in lobbyInfo.GlobalSettings.Mods )
                Console.WriteLine("- {0}", m);

            try
            {
                listener.Start();
            }
            catch (Exception)
            {
                throw new InvalidOperationException( "Unable to start server: port is already in use" );
            }

            new Thread( _ =>
            {
                for( ; ; )
                {
                    var checkRead = new ArrayList();
                    checkRead.Add( listener.Server );
                    foreach( var c in conns ) checkRead.Add( c.socket );

                    var isSendingPackages = conns.Any( c => c.Stream != null );

                    /* msdn lies, -1 doesnt work. this is ~1h instead. */
                    Socket.Select( checkRead, null, null, isSendingPackages ? DownloadChunkInterval : MasterPingInterval * 1000000 );

                    foreach( Socket s in checkRead )
                        if( s == listener.Server ) AcceptConnection();
                        else conns.Single( c => c.socket == s ).ReadData();

                    foreach( var c in conns.Where( a => a.Stream != null ).ToArray() )
                        SendNextChunk( c );

                    if (Environment.TickCount - lastPing > MasterPingInterval * 1000)
                        PingMasterServer();
                }
            } ) { IsBackground = true }.Start();
        }
Example #3
0
 static void OnServerEmpty()
 {
     Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
     inFlightFrames.Clear();
     lobbyInfo = new Session();
     lobbyInfo.GlobalSettings.Mods = initialMods;
     lobbyInfo.GlobalSettings.RandomSeed = randomSeed;
     GameStarted = false;
 }
Example #4
0
 public void AddLine(Session.Client p, string text)
 {
     AddLine(Player.PlayerColors[p.PaletteIndex].c, p.Name, text);
 }