Changeset 319
- Timestamp:
- 09/29/07 03:03:46 (16 months ago)
- Location:
- TwitterIrcGateway
- Files:
-
- 9 modified
-
TwitterIrcGateway/App.config (modified) (1 diff)
-
TwitterIrcGateway/Program.cs (modified) (1 diff)
-
TwitterIrcGateway/Settings.Designer.cs (modified) (1 diff)
-
TwitterIrcGateway/Settings.settings (modified) (1 diff)
-
TwitterIrcGatewayCLI/Program.cs (modified) (4 diffs)
-
TwitterIrcGatewayCore/Server.cs (modified) (1 diff)
-
TwitterIrcGatewayCore/Session.cs (modified) (11 diffs)
-
TwitterIrcGatewayCore/TwitterIrcGatewayCore.csproj (modified) (1 diff)
-
TwitterIrcGatewayCore/TwitterService.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
TwitterIrcGateway/TwitterIrcGateway/App.config
r85 r319 41 41 <value>False</value> 42 42 </setting> 43 <setting name="TwitterChannelName" serializeAs="String"> 44 <value>twitter</value> 45 </setting> 43 46 </Misuzilla.Applications.TwitterIrcGateway.Settings> 44 47 </userSettings> -
TwitterIrcGateway/TwitterIrcGateway/Program.cs
r84 r319 55 55 _server.IntervalDirectMessage = _settings.IntervalDirectMessage; 56 56 _server.CookieLoginMode = _settings.CookieLoginMode; 57 _server.ChannelName = "#"+_settings.TwitterChannelName; 57 58 _server.SessionStartedRecieved += new EventHandler<SessionStartedEventArgs>(_server_SessionStartedRecieved); 58 59 try -
TwitterIrcGateway/TwitterIrcGateway/Settings.Designer.cs
r85 r319 155 155 } 156 156 } 157 158 [global::System.Configuration.UserScopedSettingAttribute()] 159 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 160 [global::System.Configuration.DefaultSettingValueAttribute("twitter")] 161 public string TwitterChannelName { 162 get { 163 return ((string)(this["TwitterChannelName"])); 164 } 165 set { 166 this["TwitterChannelName"] = value; 167 } 168 } 157 169 } 158 170 } -
TwitterIrcGateway/TwitterIrcGateway/Settings.settings
r85 r319 36 36 <Value Profile="(Default)">False</Value> 37 37 </Setting> 38 <Setting Name="TwitterChannelName" Type="System.String" Scope="User"> 39 <Value Profile="(Default)">twitter</Value> 40 </Setting> 38 41 </Settings> 39 42 </SettingsFile> -
TwitterIrcGateway/TwitterIrcGatewayCLI/Program.cs
r85 r319 24 24 IPAddress bindAddress = IPAddress.Loopback; 25 25 Encoding encoding = Encoding.GetEncoding("ISO-2022-JP"); 26 String channelName = "#twitter"; 26 27 27 28 foreach (String arg in args) … … 105 106 } 106 107 } 108 else if (arg.StartsWith("--channel-name=")) 109 { 110 String channelNameT = arg.Substring("--channel-name=".Length).Replace(" ", ""); 111 if (channelName.Length != 0) 112 { 113 channelName = "#"+channelNameT; 114 } 115 } 107 116 else if (arg.StartsWith("--help")) 108 117 { … … 122 131 _server.IntervalDirectMessage = intervalDirectMessage; 123 132 _server.CookieLoginMode = cookieLoginMode; 133 _server.ChannelName = channelName; 124 134 _server.SessionStartedRecieved += new EventHandler<SessionStartedEventArgs>(_server_SessionStartedRecieved); 125 135 … … 135 145 Console.WriteLine("[Configuration] IntervalDirectMessage: {0}", _server.IntervalDirectMessage); 136 146 Console.WriteLine("[Configuration] CookieLoginMode: {0}", _server.CookieLoginMode); 147 Console.WriteLine("[Configuration] ChannelName: {0}", _server.ChannelName); 137 148 138 149 _server.Start(bindAddress, port); -
TwitterIrcGateway/TwitterIrcGatewayCore/Server.cs
r84 r319 54 54 public Boolean CookieLoginMode = false; 55 55 56 /// <summary> 57 /// Twitter�̃X�e�[�^�X�������`�����l���� 58 /// </summary> 59 public String ChannelName = "#twitter"; 60 56 61 public const String ServerName = "localhost"; 57 public const String ChannelName = "#twitter";58 62 public const String ServerNick = "$twitterGatewayServer$"; 59 63 -
TwitterIrcGateway/TwitterIrcGatewayCore/Session.cs
r84 r319 373 373 foreach (String channelName in channelNames) 374 374 { 375 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, Server.ChannelName, true) == 0)375 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, _server.ChannelName, true) == 0) 376 376 { 377 377 SendErrorReply(ErrorReply.ERR_NOSUCHCHANNEL, "No such nick/channel"); … … 410 410 foreach (String channelName in channelNames) 411 411 { 412 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, Server.ChannelName, true) == 0)412 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, _server.ChannelName, true) == 0) 413 413 { 414 414 SendErrorReply(ErrorReply.ERR_NOSUCHCHANNEL, "No such nick/channel"); … … 536 536 String channelName = e.Message.CommandParams[1]; 537 537 Trace.WriteLine(String.Format("Invite: {0} -> {1}", userName, channelName)); 538 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, Server.ChannelName, true) == 0)538 if (!channelName.StartsWith("#") || channelName.Length < 3 || String.Compare(channelName, _server.ChannelName, true) == 0) 539 539 { 540 540 SendErrorReply(ErrorReply.ERR_NOSUCHCHANNEL, "No such nick/channel"); … … 591 591 , String.Format("{0} {1}-{2} {3} {4}", Environment.MachineName, t.FullName, t.Assembly.GetName().Version, "", "")); 592 592 593 JoinMessage joinMsg = new JoinMessage( Server.ChannelName, "");593 JoinMessage joinMsg = new JoinMessage(_server.ChannelName, ""); 594 594 PrivMsgMessage autoMsg = new PrivMsgMessage(); 595 595 autoMsg.SenderNick = Server.ServerNick; 596 596 autoMsg.SenderHost = "twitter@" + Server.ServerName; 597 autoMsg.Receiver = Server.ChannelName;597 autoMsg.Receiver = _server.ChannelName; 598 598 autoMsg.Content = "Twitter IRC Gateway Server Connected."; 599 599 … … 651 651 { 652 652 // チャンネル宛は自分のメッセージを書き換え 653 if ( message.Receiver == Server.ChannelName|| message.Receiver.StartsWith("#"))653 if ((String.Compare(message.Receiver, _server.ChannelName, true) == 0) || message.Receiver.StartsWith("#")) 654 654 { 655 655 try … … 675 675 if (_server.SetTopicOnStatusChanged) 676 676 { 677 TopicMessage topicMsg = new TopicMessage( Server.ChannelName, message.Content);677 TopicMessage topicMsg = new TopicMessage(_server.ChannelName, message.Content); 678 678 topicMsg.Sender = _clientHost; 679 679 Send(topicMsg); … … 877 877 })); 878 878 879 SendNumericReply(NumericReply.RPL_NAMREPLY, "=", Server.ChannelName, String.Join(" ", _nickNames.ToArray()));880 SendNumericReply(NumericReply.RPL_ENDOFNAMES, Server.ChannelName, "End of NAMES list");879 SendNumericReply(NumericReply.RPL_NAMREPLY, "=", _server.ChannelName, String.Join(" ", _nickNames.ToArray())); 880 SendNumericReply(NumericReply.RPL_ENDOFNAMES, _server.ChannelName, "End of NAMES list"); 881 881 } 882 882 catch (WebException ex) … … 927 927 if (!_nickNames.Contains(screenName)) 928 928 { 929 JoinMessage joinMsg = new JoinMessage( Server.ChannelName, "");929 JoinMessage joinMsg = new JoinMessage(_server.ChannelName, ""); 930 930 joinMsg.SenderNick = screenName; 931 931 joinMsg.SenderHost = String.Format("{0}@{1}", "twitter", Server.ServerName); … … 938 938 if (!screenNames.Contains(screenName)) 939 939 { 940 PartMessage partMsg = new PartMessage( Server.ChannelName, "");940 PartMessage partMsg = new PartMessage(_server.ChannelName, ""); 941 941 partMsg.SenderNick = screenName; 942 942 partMsg.SenderHost = String.Format("{0}@{1}", "twitter", Server.ServerName); … … 1035 1035 noticeMsg.SenderNick = status.User.ScreenName; 1036 1036 noticeMsg.SenderHost = "twitter@" + Server.ServerName; 1037 noticeMsg.Receiver = Server.ChannelName;1037 noticeMsg.Receiver = _server.ChannelName; 1038 1038 noticeMsg.Content = String.Format("{0}: {1}", status.CreatedAt.ToString("HH:mm"), line); 1039 1039 Send(noticeMsg); … … 1045 1045 { 1046 1046 case "NOTICE": 1047 msg = new NoticeMessage( Server.ChannelName, line);1047 msg = new NoticeMessage(_server.ChannelName, line); 1048 1048 break; 1049 1049 case "PRIVMSG": 1050 1050 default: 1051 msg = new PrivMsgMessage( Server.ChannelName, line);1051 msg = new PrivMsgMessage(_server.ChannelName, line); 1052 1052 break; 1053 1053 } -
TwitterIrcGateway/TwitterIrcGatewayCore/TwitterIrcGatewayCore.csproj
r60 r319 48 48 <Compile Include="Server.cs" /> 49 49 <Compile Include="Session.cs" /> 50 <Compile Include="TwitterService.cs" /> 50 <Compile Include="TwitterService.cs"> 51 </Compile> 51 52 <Compile Include="Utility.cs" /> 52 53 </ItemGroup> -
TwitterIrcGateway/TwitterIrcGatewayCore/TwitterService.cs
r84 r319 24 24 public static readonly String ServiceServerPrefix = "http://twitter.com"; 25 25 public static readonly String Referer = "http://twitter.com/home"; 26 public static readonly String ClientUrl = "http://www.misuzilla.org/dist/net/twitterircgateway/ client-info.xml";26 public static readonly String ClientUrl = "http://www.misuzilla.org/dist/net/twitterircgateway/"; 27 27 public static readonly String ClientVersion = typeof(TwitterService).Assembly.GetName().Version.ToString(); 28 28 public static readonly String ClientName = "TwitterIrcGateway"; … … 402 402 url = TwitterService.ServiceServerPrefix + url; 403 403 Retry: 404 using (CookieEnabledWebClient webClient = new CookieEnabledWebClient(_cookies)) 405 { 406 try 407 { 408 System.Diagnostics.Trace.WriteLine(String.Format("GET(Cookie): {0}", url)); 409 return webClient.DownloadString(url); 410 } 411 catch (WebException we) 412 { 413 HttpWebResponse wResponse = we.Response as HttpWebResponse; 414 if (wResponse == null || wResponse.StatusCode != HttpStatusCode.Unauthorized || isRetry) 415 throw; 416 417 _cookies = Login(_userName, _credential.GetCredential(new Uri("http://twitter.com"), "Basic").Password); 418 419 isRetry = true; 420 goto Retry; 421 } 422 } 423 } 424 404 try 405 { 406 System.Diagnostics.Trace.WriteLine(String.Format("GET(Cookie): {0}", url)); 407 return DownloadString(url); 408 } 409 catch (WebException we) 410 { 411 HttpWebResponse wResponse = we.Response as HttpWebResponse; 412 if (wResponse == null || wResponse.StatusCode != HttpStatusCode.Unauthorized || isRetry) 413 throw; 414 415 _cookies = Login(_userName, _credential.GetCredential(new Uri("http://twitter.com"), "Basic").Password); 416 417 isRetry = true; 418 goto Retry; 419 } 420 } 421 422 private CookieCollection Login(String userNameOrEmail, String password) 423 { 424 System.Diagnostics.Trace.WriteLine(String.Format("Cookie Login: {0}", userNameOrEmail)); 425 426 HttpWebRequest request = CreateWebRequest("http://twitter.com/sessions") as HttpWebRequest; 427 request.AllowAutoRedirect = false; 428 request.Method = "POST"; 429 using (StreamWriter sw = new StreamWriter(request.GetRequestStream())) 430 { 431 sw.Write("username_or_email={0}&password={1}&remember_me=1&commit=Sign%20In", userNameOrEmail, password); 432 } 433 434 HttpWebResponse response = request.GetResponse() as HttpWebResponse; 435 using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) 436 { 437 String responseBody = sr.ReadToEnd(); 438 439 if (response.Cookies.Count == 0) 440 { 441 throw new ApplicationException("���O�C���Ɏ��s���܂����B���[�U���܂��̓p�X���[�h���Ԉ��Ă����\�����������B"); 442 } 443 444 foreach (Cookie cookie in response.Cookies) 445 { 446 cookie.Domain = "twitter.com"; 447 } 448 return response.Cookies; 449 } 450 } 451 452 WebRequest CreateWebRequest(String uri) 453 { 454 WebRequest request = WebRequest.Create(uri); 455 if (request is HttpWebRequest) 456 { 457 HttpWebRequest httpRequest = request as HttpWebRequest; 458 httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; 459 httpRequest.Referer = Referer; 460 httpRequest.PreAuthenticate = false; 461 httpRequest.Accept = "*/*"; 462 httpRequest.CookieContainer = new CookieContainer(); 463 if (_cookies != null) 464 { 465 httpRequest.CookieContainer.Add(_cookies); 466 } 467 } 468 return request; 469 } 470 471 #if FALSE 425 472 private CookieCollection Login(String userNameOrEmail, String password) 426 473 { … … 447 494 } 448 495 } 449 450 496 class CookieEnabledWebClient : WebClient 451 497 { … … 501 547 return response; 502 548 } 549 } 550 #endif 551 552 String DownloadString(String url) 553 { 554 WebRequest request = CreateWebRequest(url); 555 WebResponse response = null; 556 try 557 { 558 response = request.GetResponse(); 559 using (StreamReader sr = new StreamReader(response.GetResponseStream())) 560 { 561 return sr.ReadToEnd(); 562 } 563 } 564 finally 565 { 566 if (response != null) 567 { 568 response.Close(); 569 } 570 } 571 #if FALSE 572 using (CookieEnabledWebClient webClient = new CookieEnabledWebClient(_cookies)) 573 { 574 return webClient.DownloadString(url); 575 } 576 #endif 503 577 } 504 578 #endregion
