Пример #1
0
        public Guid?Connect(long keyId, string vCode, long solarsystemID)
        {
            // check for connection with same keyId & vCode
            int hashCode = new { keyId, vCode }.GetHashCode();

            lock (_ClientsLock) {
                Guid clientId;
                if (_ClientHashes.TryGetValue(hashCode, out clientId))
                {
                    _ClientHashes.Remove(hashCode);
                    // inform first client and disconnect him
                    DelayedBroadcast(new BroadcastMessage {
                        Action = client => {
                            client.SecondConnection(solarsystemID);
                            lock (_ClientsLock) {
                                _Clients.Remove(clientId);
                            }
                        },
                        DebugInfo = "SecondConnection",
                        Clients   = new[] { clientId }
                    });
                    DelayedBroadcast(new BroadcastMessage {
                        Action    = client => { client.ClientCountUpdate(_Clients.Count); },
                        DebugInfo = "ClientCountUpdate"
                    });
                    _Logger.Info("Dupliacate connection: " + keyId);
                    return(null);
                }
            }

            // get client callback
            IEveIntelCallback callback;

            try {
                callback = OperationContext.Current.GetCallbackChannel <IEveIntelCallback>();
            } catch (Exception exc) {
                _Logger.Error("Connect: get IEveIntelCallback: ", exc);
                // invalid client
                return(null);
            }

            // connect to eve api and get all player character names
            Dictionary <long, string> characters;

            try {
                EveApi eveApi = new EveApi(keyId, vCode);
                characters = eveApi.GetAccountEntries().ToDictionary(o => o.CharacterID, o => o.Name);
            } catch (Exception) {
                // invalid key/vCode
                _Logger.Warn("Connect: invalid key/vCode: " + keyId + ", '" + vCode + "'");
                return(null);
            }

            if (characters.Count == 0)
            {
                _Logger.Warn("Connect: invalid key/vCode (no characters): " + keyId + ", '" + vCode + "'");
                return(null);
            }

            // kos check against all player characters
            EveIntelCharacterInfo[] characterInfos = GetEveIntelCharacterInfos(solarsystemID, characters);
            EveIntelCharacterInfo[] kosInfos       = characterInfos.Where(o => o.Kos).ToArray();
            if (kosInfos.Length > 0)
            {
                _Logger.Warn("Connect: kos characters: '" + string.Join("', '", kosInfos.Select(o => o.CharacterName)));
                return(null);
            }

            // generate client id
            Guid result = Guid.NewGuid();

            lock (_ClientsLock) {
                _Clients.Add(result, new ClientInfo {
                    Callback = callback,
                    KeyId    = keyId,
                    VCode    = vCode,
                    HashCode = hashCode
                });

                // DEBUG CODE
                if (!_ClientHashes.ContainsKey(hashCode))
                {
                    _ClientHashes.Add(hashCode, result);
                }
            }

            DelayedBroadcast(new BroadcastMessage {
                Action    = client => { client.ClientCountUpdate(_Clients.Count); },
                DebugInfo = "ClientCountUpdate"
            });

            _Logger.Info("Connect: " + result + " (" + string.Join(", ", characterInfos.Select(o => o.CharacterName)) + ")");
            return(result);
        }
Пример #2
0
 public bool CheckApiKey(EveApiKey apiKey)
 {
     var anonApi = new EveApi(apiKey.KeyId, apiKey.VCode);
     return anonApi.GetAccountEntries().Count > 0;
 }
Пример #3
0
        public Guid? Connect(long keyId, string vCode, long solarsystemID)
        {
            // check for connection with same keyId & vCode
            int hashCode = new {keyId, vCode}.GetHashCode();
            lock (_ClientsLock) {
                Guid clientId;
                if (_ClientHashes.TryGetValue(hashCode, out clientId)) {
                    _ClientHashes.Remove(hashCode);
                    // inform first client and disconnect him
                    DelayedBroadcast(new BroadcastMessage {
                        Action = client => {
                            client.SecondConnection(solarsystemID);
                            lock (_ClientsLock) {
                                _Clients.Remove(clientId);
                            }
                        },
                        DebugInfo = "SecondConnection",
                        Clients = new[] {clientId}
                    });
                    DelayedBroadcast(new BroadcastMessage {
                        Action = client => { client.ClientCountUpdate(_Clients.Count); },
                        DebugInfo = "ClientCountUpdate"
                    });
                    _Logger.Info("Dupliacate connection: " + keyId);
                    return null;
                }
            }

            // get client callback
            IEveIntelCallback callback;
            try {
                callback = OperationContext.Current.GetCallbackChannel<IEveIntelCallback>();
            } catch (Exception exc) {
                _Logger.Error("Connect: get IEveIntelCallback: ", exc);
                // invalid client
                return null;
            }

            // connect to eve api and get all player character names
            Dictionary<long, string> characters;
            try {
                EveApi eveApi = new EveApi(keyId, vCode);
                characters = eveApi.GetAccountEntries().ToDictionary(o => o.CharacterID, o => o.Name);
            } catch (Exception) {
                // invalid key/vCode
                _Logger.Warn("Connect: invalid key/vCode: " + keyId + ", '" + vCode + "'");
                return null;
            }

            if (characters.Count == 0) {
                _Logger.Warn("Connect: invalid key/vCode (no characters): " + keyId + ", '" + vCode + "'");
                return null;
            }

            // kos check against all player characters
            EveIntelCharacterInfo[] characterInfos = GetEveIntelCharacterInfos(solarsystemID, characters);
            EveIntelCharacterInfo[] kosInfos = characterInfos.Where(o => o.Kos).ToArray();
            if (kosInfos.Length > 0) {
                _Logger.Warn("Connect: kos characters: '" + string.Join("', '", kosInfos.Select(o => o.CharacterName)));
                return null;
            }

            // generate client id
            Guid result = Guid.NewGuid();
            lock (_ClientsLock) {
                _Clients.Add(result, new ClientInfo {
                    Callback = callback,
                    KeyId = keyId,
                    VCode = vCode,
                    HashCode = hashCode
                });

                // DEBUG CODE
                if (!_ClientHashes.ContainsKey(hashCode)) {
                    _ClientHashes.Add(hashCode, result);
                }
            }

            DelayedBroadcast(new BroadcastMessage {
                Action = client => { client.ClientCountUpdate(_Clients.Count); },
                DebugInfo = "ClientCountUpdate"
            });

            _Logger.Info("Connect: " + result + " (" + string.Join(", ", characterInfos.Select(o => o.CharacterName)) + ")");
            return result;
        }