public override void process(Server server, Server.Client client)
        {
            location = Multiplayer.processLocationNameForPlayerUnique(client.farmer, location);

            process();
            server.broadcast(this, client.id);
        }
예제 #2
0
        public override void process(Server server, Server.Client client)
        {
            ChatMenu.chat.Add(new ChatEntry(null, client.farmer.name + " is in bed."));
            server.broadcast(new ChatPacket(255, client.farmer.name + " is in bed."), client.id);

            // This is also set in ClientFarmerDataPacket.
            // I think what's happening is this packet is received, and it goes to the next day.
            // When the next day starts it sees the ClientFarmerDataPacket, and resets this same thing.
            // So the host is ignoring everything the clients do, and queueing their messages up until
            // whenever the stage is set back to Playing. Then all of the clients changes come out at once.
            // The clients are oblivious and still receiving the host updates though.
            //
            // (Of course, I can't reproduce this since I assume it is latency related again, made even
            // weirder with the receiving being on another thread.)
            //
            // Hopefully only setting this in the latter packet will fix this.
            //
            // Actually, that^ might be completely wrong.

            //client.stage = Server.Client.NetStage.WaitingForStart;
            if (client.farmer.currentLocation != null)
            {
                ;// client.farmer.currentLocation.farmers.Remove(client.farmer);
            }
        }
 public virtual void ServerAction(Lobby lobby, Server.Client client)
 {
     if (serverEntity)
     {
         lobby.RemoveNetworkEntity(clientIndex, entityIndex);
     }
 }
예제 #4
0
        public override void process(Server server, Server.Client client)
        {
            Log.trace("Got version packet");
            if (client.stage != Server.Client.NetStage.VerifyingVersion)
            {
                Log.debug("Got version packet at wrong stage");
                //return;
            }

            if (version == Multiplayer.PROTOCOL_VERSION)
            {
                client.stage = Server.Client.NetStage.WaitingForFarmerInfo;
                if (!client.sentId)
                {
                    Log.trace("Sending ID packet " + client.id);
                    client.send(new YourIDPacket(client.id));
                    client.sentId = true;
                }
            }
            else
            {
                Log.trace("Bad version from client " + client.id);
                client.stageFailed = true;
            }
        }
예제 #5
0
        public override void process(Server server, Server.Client client)
        {
            //redirect the packet to all connected clients to avoid item/data loss
            server.broadcast(this, client.id);
            location = Multiplayer.processLocationNameForPlayerUnique(client.farmer, location);

            process();
        }
예제 #6
0
        public override void process(Server server, Server.Client client)
        {
            if (clientId != client.id)
            {
                return;
            }

            doFarmer(client.farmer);
            server.broadcast(this, client.id);
        }
예제 #7
0
        public override void process(Server server, Server.Client client)
        {
            if (clientId != client.id)
            {
                return;
            }

            //Log.Async("Movement " + flags + " " + x + " " + y);
            doFarmer(client.farmer);

            server.broadcast(this, clientId);
        }
예제 #8
0
 public override void process(Server server, Server.Client client)
 {
     if (version == Multiplayer.PROTOCOL_VERSION)
     {
         client.stage = Server.Client.NetStage.WaitingForFarmerInfo;
         client.send(new YourIDPacket(client.id));
     }
     else
     {
         client.stageFailed = true;
     }
 }
예제 #9
0
        public override void process(Server server, Server.Client client)
        {
            name = Multiplayer.processLocationNameForPlayerUnique(client.farmer, name);

            if (clientId != client.id)
            {
                return;
            }
            Log.Async(client.farmer.name + " moved to " + name + " (" + Game1.getLocationFromName(name) + ")");

            process(client.farmer);

            server.broadcast(this, clientId);
        }
예제 #10
0
    private static void ProccesGameResult(Game.Result result, Server.Client a, Server.Client b, Server.Lobby lobby)
    {
        switch (result.type)
        {
        case Game.Result.Type.Ok:
            if (result.winner != null)
            {
                Console.WriteLine("winner: {0}", result.winner.name);
            }
            else
            {
                Console.WriteLine("tie {0} between {1}", a.name, b.name);
            }
            break;

        case Game.Result.Type.Error:
            Console.WriteLine("some error while playing");

            if (a.client.Client.IsConnected() && !b.client.Client.IsConnected())
            {
                Message.Util.Send(a.client.GetStream(), new Message.OpponentDisconnected());
            }

            if (!a.client.Client.IsConnected() && b.client.Client.IsConnected())
            {
                Message.Util.Send(b.client.GetStream(), new Message.OpponentDisconnected());
            }

            break;
        }

        if (a.client.Client.IsConnected())
        {
            lobby.Enter(a);
        }
        else
        {
            Console.WriteLine("{0} disconnected while playing", a);
        }

        if (b.client.Client.IsConnected())
        {
            lobby.Enter(b);
        }
        else
        {
            Console.WriteLine("{0} disconnected while playing", b);
        }
    }
예제 #11
0
        public void ServerAction(Lobby lobby, Server.Client client)
        {
            lock (lobby.entityCheckLock)
            {
                //Check for existing
                NetworkEntity[] networkEntities = lobby.NetworkEntities;
                for (int i = 0; i < networkEntities.Length; i++)
                {
                    if (networkEntities[i].ClientIndex == networkEntityData.ClientIndex && networkEntities[i].EntityIndex == networkEntityData.EntityIndex)
                    {
                        //Set data
                        networkEntityData.SetNetworkEntity(networkEntities[i], null);
                        return;
                    }
                }

                //None exist, create new
                lobby.AddNetworkEntity(networkEntityData.DeployNetworkEntity(null, null, lobby));
            }
        }
예제 #12
0
        public override void process(Server server, Server.Client client)
        {
            state.defaultMap = Multiplayer.processLocationNameForPlayerUnique(client.farmer, state.defaultMap);

            if (name == Game1.player.spouse)
            {
                return;
            }
            foreach (Server.Client other in server.clients)
            {
                if (other == client)
                {
                    continue;
                }
                if (name == other.farmer.spouse)
                {
                    return;
                }
            }

            process();
            server.broadcast(this, client.id);
        }
예제 #13
0
        public Result Play()
        {
            board.Clear();
            playerIndex = -1;
            Server.Client winner = null;

            Console.WriteLine("Game::Play(), match starting");

            while (winner == null && board.HasAnyEmpty)
            {
                playerIndex = NextPlayerIndex;
                Server.Client currentPlayer = players[playerIndex];

                Console.WriteLine("Game::Play(), {0} turn", currentPlayer.symbol.ToString());

                Position         position;
                Message.Position positionMsg;

                try {
                    Message.BaseMessage message = Message.Util.Receive(currentPlayer.client.GetStream(), Message.Position.TypeId);
                    positionMsg = (Message.Position)message;
                    position    = new Position(positionMsg.i, positionMsg.j);
                }
                catch (Message.NothingReceivedException)
                {
                    Result errorResult = new Result();
                    errorResult.type = Result.Type.Error;
                    return(errorResult);
                }

                Console.WriteLine("Game::Play(), received position {0}", position);

                board.Mark(position, currentPlayer.symbol);

                Server.Client nextPlayer = players[NextPlayerIndex];
                bool          sentOk     = Message.Util.Send(nextPlayer.client.GetStream(), positionMsg);
                if (!sentOk)
                {
                    Result errorResult = new Result();
                    errorResult.type = Result.Type.Error;
                    return(errorResult);
                }


                if (board.HasWon(position))
                {
                    winner = currentPlayer;
                }
            }

            Result okResult = new Result();

            okResult.type = Result.Type.Ok;

            if (board.HasAnyEmpty)
            {
                okResult.winner = winner;
            }

            return(okResult);
        }
예제 #14
0
 public virtual void process(Server server, Server.Client client)
 {
 }
예제 #15
0
 public void ServerAction(Lobby lobby, Server.Client client)
 {
     lobby.PrintMethod.Invoke("TEST MESSAGE ARRIVED FROM: " + client.ClientInfo.Username);
 }
예제 #16
0
 public override void process(Server server, Server.Client client)
 {
     process();
     server.broadcast(this, client.id);
 }
예제 #17
0
 public void ServerAction(Lobby lobby, Server.Client client)
 {
     client.IsReady = true;
     lobby.CheckReadiness();
 }
        public override void process(Server server, Server.Client client)
        {
            Log.debug("Got farmer data for client " + client.id);

            //SFarmer old = client.farmer;
            SaveGame theirs = (SaveGame)SaveGame.serializer.Deserialize(Util.stringStream(xml));

            if (client.farmer == null)
            {
                ChatMenu.chat.Add(new ChatEntry(null, theirs.player.name + " has connected."));
                server.broadcast(new ChatPacket(255, theirs.player.name + " has connected."), client.id);

                String str = "Currently playing: ";
                str += NewLoadMenu.pendingSelected.name;
                foreach (Server.Client other in server.clients)
                {
                    if (other == client || other.farmer == null)
                    {
                        continue;
                    }
                    str += ", " + other.farmer.name;
                }
                client.send(new ChatPacket(255, str));
            }

            client.farmerXml = Util.serialize <SFarmer>(theirs.player);
            client.farmer    = theirs.player;
            client.farmer.uniqueMultiplayerID += 1 + client.id;

            NewSaveGame.loadDataToFarmer(client.farmer);
            client.farmer.FarmerSprite.setOwner(client.farmer);
            Game1.player.FarmerSprite.setOwner(Game1.player);

            //if(!server.playing)
            //if (server.playing) client.farmer = old;

            // About second-day-sleeping crashes:
            // So just adding the location directly puts the raw deserialized one into the game.
            // The raw deserialized one doesn't have the tiles and stuff loaded. Just the game data.
            // I think this is why vanilla copies data over in loadDataToLocations instead of using
            // the loaded objects directly. Why not just postpone loading until later, I don't know.
            //
            // So, when the second day begins, otherFarmer.currentLocation was still set to the
            // previous day's farm house[*]. On day two, the 'good' one[**] was removed, so when they go
            // back in, the bad one is used. Basically, I need to make them all the 'good' one.
            // For now, I'm just going to reload the needed data for this client's farmhouse.
            // I'll figure out how to do it 'properly' later. Maybe. (My mind is muddled today.)
            //
            // [*] Looking at addFixedLocationToOurWorld now you'll see that this isn't the case.
            // I added the part about fixing SFarmer.currentLocation as I was going through this
            // thought process. So things will break more obviously if something like this happens
            // again.
            //
            // [**] The first day's farmhouse is okay because in loadDataToLocations, (called in
            // NewSaveGame.getLoadEnumerator), the map is reloaded from FarmHouse_setMapForUpgradeLevel.
            // If CO-OP weren't on, worse things would happen, because things besides the farm house
            // would need loading (see Multiplayer.isPlayerUnique). The client doesn't have this
            // issue because they do the whole loading process each day anyways.
            //
            // Of course, the whole second-day-crash doesn't happen when I test it on localhost. Hence
            // why this was so annoying. And probably why I documented all this.
            foreach (GameLocation theirLoc in theirs.locations)
            {
                if (theirLoc.name == "FarmHouse")
                {
                    NewSaveGame.FarmHouse_setMapForUpgradeLevel(theirLoc as FarmHouse);
                }
            }

            fixPetDuplicates(theirs);

            Multiplayer.fixLocations(theirs.locations, client.farmer, addFixedLocationToOurWorld, client);

            foreach (string mail in Multiplayer.checkMail)
            {
                if (client.farmer.mailForTomorrow.Contains(mail))
                {
                    if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail))
                    {
                        SaveGame.loaded.player.mailForTomorrow.Add(mail);
                    }
                    if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail))
                    {
                        Game1.player.mailForTomorrow.Add(mail);
                    }
                }
                if (client.farmer.mailForTomorrow.Contains(mail + "%&NL&%"))
                {
                    if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                    {
                        SaveGame.loaded.player.mailForTomorrow.Add(mail + "%&NL&%");
                    }
                    if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                    {
                        Game1.player.mailForTomorrow.Add(mail + "%&NL&%");
                    }
                }
            }

            client.stage = Server.Client.NetStage.WaitingForStart;
        }
예제 #19
0
 public ClientDisconnectMessage(Server.Client disconnectingClient)
 {
     clientIndex = disconnectingClient.ClientIndex;
 }
예제 #20
0
 public override void process(Server server, Server.Client client)
 {
     Log.trace("Updated latest ID");
     Multiplayer.prevLatestId = MultiplayerUtility.latestID = latest;
 }