Ejemplo n.º 1
0
        public static void SendServerJoinRequest()
        {
            var serverJoinRequest = new ServerJoinRequest();
            var request           = new Request(serverJoinRequest);

            Send(request);
        }
Ejemplo n.º 2
0
 public Request(ServerJoinRequest serverJoinRequest)
 {
     ServerJoinRequest = serverJoinRequest;
 }
Ejemplo n.º 3
0
        private void Process(NetPeer peer, ServerJoinRequest msg)
        {
            if (msg.username == null || msg.username.Length < 4 || msg.username.Length > 30)
            {
                SendToPeer(peer, new ServerJoinReject {
                    reason = "Invalid name"
                });
                return;
            }

            if (peers.ContainsKey(peer))
            {
                SendToPeer(peer, new ServerJoinReject {
                    reason = "Already connected"
                });
                return;
            }

            var player = state.history.GetPlayer(msg.username, msg.password);

            if (player == null)
            {
                SendToPeer(peer, new ServerJoinReject {
                    reason = "Bad login"
                });
                return;
            }

            foreach (var other in peers.Values)
            {
                if (player.id == other.player.id)
                {
                    SendToPeer(peer, new ServerJoinReject {
                        reason = "Name in use"
                    });
                    return;
                }
            }

            Client client;

            if (peers.TryGetValue(peer, out client) == false)
            {
                client = new Client(player.id, peer, player);
                peers.Add(peer, client);
            }

            client.ready = false;

            var res = state.serverInfo;

            res.timestamp = state.gameTime.GetCurrentTime();
            res.id        = client.id;

            if (player.equipmentGuid == null)
            {
                player.equipmentGuid = State.GetGuid();
            }

            res.inventoryGuid = player.inventoryGuid;
            res.equipmentGuid = player.equipmentGuid;

            SendToPeer(peer, res);

            Log.Info("Player {0} joining: {1}", client.id, client.player.username);
        }