using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Protocol { // http://luetzschena-stahmeln.de/dictd/xmllist.php public class Dict : SocketClient { #region notes // fixme: this needs to be a socket client for connecting to a dict server, getting a response, closing, and returning the definition // fixme: find a server to connect to // fixme: dict is on port 2628 // server list: http://luetzschena-stahmeln.de/dictd/index.php // * dict.org, dict.us.dict.org, dict0.us.dict.org (primary server) // * dict1.us.dict.org (backup server) // * alt0.dict.org (secondary backup server, of last resort) // * all.dict.org (DNS round-robin of dict?.us.dict.org) // test.dict.org // onconnectinitialize // onconnect // ondisconnect // onconnectionfailed // onserverlist // ondefinitionreceived // onerror // onauthenticationresult // onclientidentification // onsenderror (not connected), (unknown) // Server // Port // Username // Password #endregion #region constructor public Dict(string server, int port) { Server = server; Port = port; } #endregion #region processing protected override void DataHandler(string message) { /* DATABASES_PRESENT = '110' STRATEGIES_AVAILABLE = '111' DATABASE_INFORMATION = '112' HELP_TEXT = '113' SERVER_INFORMATION = '114' CHALLENGE_FOLLOWS = '130' DEFINITIONS_RETRIEVED = '150' WORD_DEFINITION = '151' MATCHES_PRESENT = '152' STATUS_RESPONSE = '210' CONNECTION_ESTABLISHED = '220' CLOSING_CONNECTION = '221' AUTHENTICATION_SUCCESSFUL = '230' OK = '250' SEND_RESPONSE = '330' TEMPORARILY_UNAVAILABLE = '420' SHUTTING_DOWN = '421' UNRECOGNISED_COMMAND = '500' ILLEGAL_PARAMETERS = '501' COMMAND_NOT_IMPLEMENTED = '502' PARAMETER_NOT_IMPLEMENTED = '503' ACCESS_DENIED = '530' AUTH_DENIED = '531' UNKNOWN_MECHANISM = '532' INVALID_DATABASE = '550' INVALID_STRATEGY = '551' NO_MATCH = '552' NO_DATABASES_PRESENT = '554' NO_STRATEGIES_AVAILABLE = '555' */ } #endregion #region methods public void DefineClient(string ClientName) { WriteRAW("CLIENT " + ClientName); } public void Quit() { WriteRAW("QUIT"); Disconnect(); // close the socket } public void RequestDefinition(string Database, string word) { if (Database == "") { Database = "*"; } WriteRAW("DEFINE " + Database + " \"" + word + "\""); // datamode Dict.GetDefinition } public void RequestWordMatch(string Database, string Strategy, string Word) { WriteRAW("MATCH " + Database + " " + Strategy + " " + Word); // } public void RequestDatabases() { WriteRAW("SHOW DB"); // datamode Dict.GetDatabases } public void RequestDatabaseInformation(string Database) { WriteRAW("SHOW INFO " + Database); } public void RequestStrategyList() { WriteRAW("SHOW STRAT"); // datamode Dict.GetStrategies } public void RequestServerInformation() { WriteRAW("SHOW SERVER"); // datamode Dict.GetServerInformation } public void RequestServerStatus() { WriteRAW("STATUS"); // } public void RequestHelp() { WriteRAW("HELP"); // datamode Dict.GetHelp } public void SendClientInformation(string Information) { WriteRAW("CLIENT " + Information); // datamode Dict.ClientID } public void SendAuthentication(string UserName, string Password) { // fixme: get an MD5 of the password WriteRAW("AUTH " + UserName + " " + Password); // datamode Dict.Authorizing } #endregion } }